Skip to content

Commit

Permalink
prevent forecasted grants from surfacing during dev work
Browse files Browse the repository at this point in the history
  • Loading branch information
masimons committed Sep 14, 2024
1 parent 9a69163 commit bd179de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/server/__tests__/db/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,16 @@ describe('db', () => {
const result = await db.getNewGrantsForAgency(fixtures.agencies.accountancy);
expect(result.length).to.equal(1);
});
it('does not return forecasted grants', async () => {
const newGrant = fixtures.grants.healthAide;
newGrant.grant_id = '444817';
newGrant.open_date = new Date('2022-06-21');
newGrant.opportunity_status = 'forecasted';
await knex(TABLES.grants).insert(Object.values([newGrant]));
const result = await db.getNewGrantsForAgency(fixtures.agencies.accountancy);
const forecastedGrant = result.filter((grant) => { grant.grant_id === '444817'});
expect(forecastedGrant.length).to.equal(0);
});
});

context('createUser', () => {
Expand Down
12 changes: 9 additions & 3 deletions packages/server/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ async function getNewGrantsForAgency(agency) {
.select(knex.raw(`${TABLES.grants}.*, count(*) OVER() AS total_grants`))
.modify(helpers.whereAgencyCriteriaMatch, agencyCriteria)
.modify((qb) => {
qb.where({ open_date: moment().subtract(1, 'day').format('YYYY-MM-DD') });
qb.where({ open_date: moment().subtract(1, 'day').format('YYYY-MM-DD') })
.whereNot({ opportunity_status: 'forecasted' });
})
.limit(3);

Expand Down Expand Up @@ -751,6 +752,7 @@ async function getGrantsNew(filters, paginationParams, orderingParams, tenantId,
CASE
WHEN grants.archive_date <= now() THEN 'archived'
WHEN grants.close_date <= now() THEN 'closed'
WHEN grants.open_date > now() THEN 'forecasted'
ELSE 'posted'
END as opportunity_status
`))
Expand All @@ -761,6 +763,7 @@ async function getGrantsNew(filters, paginationParams, orderingParams, tenantId,
.select(knex.raw(`
count(*) OVER() AS full_count
`))
.whereNot({ opportunity_status: 'forecasted' })
.groupBy(
'grants.grant_id',
'grants.grant_number',
Expand Down Expand Up @@ -844,6 +847,7 @@ async function getGrants({
currentPage, perPage, tenantId, filters, orderBy, searchTerm, orderDesc,
} = {}) {
const data = await knex(TABLES.grants)
.whereNot(`${TABLES.grants}.opportunity_status`, 'forecasted')
.modify((queryBuilder) => {
if (searchTerm && searchTerm !== 'null') {
queryBuilder.andWhere(
Expand Down Expand Up @@ -1005,14 +1009,16 @@ async function getGrants({
async function getGrant({ grantId }) {
const results = await knex.table(TABLES.grants)
.select('*')
.where({ grant_id: grantId });
.where({ grant_id: grantId })
.whereNot({ opportunity_status: 'forecasted'});
return results[0];
}

async function getSingleGrantDetails({ grantId, tenantId }) {
const results = await knex.table(TABLES.grants)
.select('*')
.where({ grant_id: grantId });
.where({ grant_id: grantId })
.whereNot({ opportunity_status: 'forecasted'});
const enhancedResults = await enhanceGrantData(tenantId, results);
return enhancedResults.length ? enhancedResults[0] : null;
}
Expand Down

0 comments on commit bd179de

Please sign in to comment.