Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensures opportunity_status is up to date #1920

Merged
merged 9 commits into from
Sep 18, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
as1729 marked this conversation as resolved.
Show resolved Hide resolved
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
// , ALTER COLUMN close_date TYPE timestamp USING close_date::timestamp, ADD COLUMN archive_date TYPE timestamp
return knex.raw(`ALTER TABLE grants ALTER COLUMN open_date TYPE timestamp USING open_date::timestamp,
ALTER COLUMN close_date TYPE timestamp USING close_date::timestamp,
ADD COLUMN archive_date timestamp`);
as1729 marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
// , ALTER COLUMN close_date TYPE text USING close_date::text, DROP COLUMN archive_date
return knex.raw(`ALTER TABLE grants ALTER COLUMN open_date TYPE text USING open_date::text,
ALTER COLUMN close_date TYPE text USING close_date::text,
DROP COLUMN archive_date`);
};
35 changes: 34 additions & 1 deletion packages/server/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,40 @@ function grantsQuery(queryBuilder, filters, agencyId, orderingParams, pagination
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId, agencyId) {
console.log(filters, paginationParams, orderingParams, tenantId, agencyId);
const data = await knex(TABLES.grants)
.select(`${TABLES.grants}.*`)
.select([
'grants.grant_id',
'grants.grant_number',
'grants.title',
'grants.status',
'grants.agency_code',
'grants.award_ceiling',
'grants.cost_sharing',
'grants.cfda_list',
'grants.open_date',
'grants.close_date',
'grants.reviewer_name',
'grants.opportunity_category',
'grants.search_terms',
'grants.notes',
'grants.created_at',
'grants.updated_at',
'grants.description',
'grants.eligibility_codes',
'grants.raw_body',
'grants.award_floor',
'grants.revision_id',
'grants.title_ts',
'grants.description_ts',
'grants.funding_instrument_codes',
'grants.bill',
])
.select(knex.raw(`
CASE
WHEN grants.archive_date <= now() THEN 'archived'
WHEN grants.close_date <= now() THEN 'closed'
ELSE 'posted'
END as opportunity_status
`))
.distinct()
.modify((qb) => grantsQuery(qb, filters, agencyId, orderingParams, paginationParams));

Expand Down
1 change: 1 addition & 0 deletions packages/server/src/lib/grants-ingest.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function mapSourceDataToGrant(source) {
? milestones.close.date : '2100-01-01';
const today = moment().startOf('day');
if (milestones.archive_date && today.isSameOrAfter(moment(milestones.archive_date), 'date')) {
grant.archive_date = milestones.archive_date;
grant.opportunity_status = 'archived';
} else if (today.isSameOrAfter(moment(grant.close_date), 'date')) {
grant.opportunity_status = 'closed';
Expand Down
Loading