Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
masimons committed Sep 30, 2024
1 parent 4f4e671 commit e0b63ab
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ API_DOMAIN=http://localhost:8080

ENABLE_GRANTS_SCRAPER=true
SHARE_TERMINOLOGY_ENABLED=true
SHOW_FORECASTED_GRANTS=true
GRANTS_SCRAPER_DATE_RANGE=7
GRANTS_SCRAPER_DELAY=1000
NODE_OPTIONS=--max_old_space_size=1024
Expand Down
31 changes: 22 additions & 9 deletions packages/server/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ async function getNewGrantsForAgency(agency) {
.modify(helpers.whereAgencyCriteriaMatch, agencyCriteria)
.modify((qb) => {
qb.where({ open_date: moment().subtract(1, 'day').format('YYYY-MM-DD') })

Check failure on line 352 in packages/server/src/db/index.js

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Missing semicolon
.whereNot({ opportunity_status: 'forecasted' });
})
.limit(3);

Expand Down Expand Up @@ -714,7 +713,7 @@ function addCsvData(qb) {
tenantId: number
agencyId: number
*/
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId, agencyId, toCsv) {
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId, agencyId, toCsv, showForecastedGrants=false) {

Check failure on line 716 in packages/server/src/db/index.js

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Operator '=' must be spaced
const errors = validateSearchFilters(filters);
if (errors.length > 0) {
throw new Error(`Invalid filters: ${errors.join(', ')}`);
Expand Down Expand Up @@ -760,10 +759,14 @@ async function getGrantsNew(filters, paginationParams, orderingParams, tenantId,
NULLIF(grants.award_ceiling, 0) as award_ceiling
`))
.modify((qb) => grantsQuery(qb, filters, agencyId, orderingParams, paginationParams))
.modify((qb) => {
if (!showForecastedGrants) {
qb.whereNot({ opportunity_status: 'forecasted' });
}
})
.select(knex.raw(`
count(*) OVER() AS full_count
`))
.whereNot({ opportunity_status: 'forecasted' })
.groupBy(
'grants.grant_id',
'grants.grant_number',
Expand Down Expand Up @@ -844,10 +847,9 @@ async function enhanceGrantData(tenantId, data) {
}

async function getGrants({
currentPage, perPage, tenantId, filters, orderBy, searchTerm, orderDesc,
currentPage, perPage, tenantId, filters, orderBy, searchTerm, orderDesc, showForecastedGrants

Check failure on line 850 in packages/server/src/db/index.js

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Missing trailing comma
} = {}) {
const data = await knex(TABLES.grants)
.whereNot(`${TABLES.grants}.opportunity_status`, 'forecasted')
.modify((queryBuilder) => {
if (searchTerm && searchTerm !== 'null') {
queryBuilder.andWhere(
Expand All @@ -856,6 +858,9 @@ async function getGrants({
.orWhere(`${TABLES.grants}.title`, '~*', searchTerm),
);
}
if (!showForecastedGrants) {
queryBuilder.andWhereNot(`${TABLES.grants}.opportunity_status`, 'forecasted');
}
if (filters) {
if (filters.interestedByUser || filters.positiveInterest || filters.result || filters.rejected || filters.interestedByAgency) {
queryBuilder.join(TABLES.grants_interested, `${TABLES.grants}.grant_id`, `${TABLES.grants_interested}.grant_id`)
Expand Down Expand Up @@ -1006,19 +1011,27 @@ async function getGrants({
return { data: dataWithAgency, pagination };
}

async function getGrant({ grantId }) {
async function getGrant({ grantId, showForecastedGrants }) {
const results = await knex.table(TABLES.grants)
.select('*')
.where({ grant_id: grantId })
.whereNot({ opportunity_status: 'forecasted' });
.modify((queryBuilder) => {
if (!showForecastedGrants) {
queryBuilder.whereNot({ opportunity_status: 'forecasted' });
}
})

Check failure on line 1022 in packages/server/src/db/index.js

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Missing semicolon
return results[0];
}

async function getSingleGrantDetails({ grantId, tenantId }) {
async function getSingleGrantDetails({ grantId, tenantId, showForecastedGrants }) {
const results = await knex.table(TABLES.grants)
.select('*')
.where({ grant_id: grantId })
.whereNot({ opportunity_status: 'forecasted' });
.modify((queryBuilder) => {
if (!showForecastedGrants) {
queryBuilder.whereNot({ opportunity_status: 'forecasted' });
}
})

Check failure on line 1034 in packages/server/src/db/index.js

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Missing semicolon
const enhancedResults = await enhanceGrantData(tenantId, results);
return enhancedResults.length ? enhancedResults[0] : null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/lib/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ async function sendGrantAssignedEmails({ grantId, agencyIds, userId }) {
i. Send email
*/
try {
const grant = await db.getGrant({ grantId });
const grant = await db.getGrant({ grantId, showForecastedGrants: process.env.SHOW_FORECASTED_GRANTS });
const grantDetail = await buildGrantDetail(grant, notificationType.grantAssignment);
const agencies = await db.getAgenciesByIds(agencyIds);
await asyncBatch(
Expand Down
5 changes: 4 additions & 1 deletion packages/server/src/routes/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ router.get('/', requireUser, async (req, res) => {
},
orderBy: req.query.orderBy,
orderDesc: req.query.orderDesc,
showForecastedGrants: process.env.SHOW_FORECASTED_GRANTS,
});
res.json(grants);
});
Expand Down Expand Up @@ -124,6 +125,7 @@ router.get('/next', requireUser, async (req, res) => {
user.tenant_id,
user.agency_id,
false,
process.env.SHOW_FORECASTED_GRANTS,
);

return res.json(grants);
Expand All @@ -133,7 +135,7 @@ router.get('/next', requireUser, async (req, res) => {
router.get('/:grantId/grantDetails', requireUser, async (req, res) => {
const { grantId } = req.params;
const { user } = req.session;
const response = await db.getSingleGrantDetails({ grantId, tenantId: user.tenant_id });
const response = await db.getSingleGrantDetails({ grantId, tenantId: user.tenant_id, showForecastedGrants: process.env.SHOW_FORECASTED_GRANTS });
res.json(response);
});

Expand All @@ -160,6 +162,7 @@ router.get('/exportCSVNew', requireUser, async (req, res) => {
user.tenant_id,
user.agency_id,
true,
process.env.SHOW_FORECASTED_GRANTS,
);

// Generate CSV
Expand Down
1 change: 1 addition & 0 deletions terraform/prod.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ api_datadog_environment_variables = {
api_container_environment = {
NEW_GRANT_DETAILS_PAGE_ENABLED = true,
SHARE_TERMINOLOGY_ENABLED = true,
SHOW_FORECASTED_GRANTS = false,
}

// Postgres
Expand Down
1 change: 1 addition & 0 deletions terraform/staging.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ api_datadog_environment_variables = {
api_container_environment = {
NEW_GRANT_DETAILS_PAGE_ENABLED = true,
SHARE_TERMINOLOGY_ENABLED = true,
SHOW_FORECASTED_GRANTS = true,
}

// Postgres
Expand Down

0 comments on commit e0b63ab

Please sign in to comment.