Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into chore/1090-remove-unused-v…
Browse files Browse the repository at this point in the history
…alidate-data
  • Loading branch information
Vikariusu committed Nov 21, 2023
2 parents f7e1a7d + c98cf19 commit 3ae93db
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 26 deletions.
19 changes: 16 additions & 3 deletions packages/server/__tests__/api/grants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ describe('`/api/grants` endpoint', () => {
'Title',
'Viewed By',
'Interested Teams',
'Status',
'Opportunity Status',
'Opportunity Category',
'Cost Sharing',
'Award Ceiling',
Expand All @@ -487,11 +487,24 @@ describe('`/api/grants` endpoint', () => {
'Agency Code',
'Grant Id',
'URL',
'Funding Type',
'Appropriations Bill',
'Agency Code',
'Eligibility',
];

const txt = await response.text();
const rows = txt.split('\n');
expect(rows[0]).to.equal(expectedCsvHeaders.join(','));

const cells = rows[1].split(',');
const valMap = new Map([...Array(cells.length).keys()].map((i) => [expectedCsvHeaders[i], cells[i]]));

expect(txt.split('\n')[0]).to.equal(expectedCsvHeaders.join(','));
expect(txt.split('\n')[1]).to.contain('HHS-2021-IHS-TPI-0001,Community Health Aide Program: Tribal Planning &');
expect(valMap.get('Opportunity Number')).to.equal('HHS-2021-IHS-TPI-0001');
expect(valMap.get('Title')).to.equal('Community Health Aide Program: Tribal Planning & Implementation');
expect(valMap.get('Funding Type')).to.equal('Other');
expect(valMap.get('Agency Code')).to.equal('HHS-IHS');
expect(valMap.get('Eligibility')).to.equal('"Native American tribal organizations (other than Federally recognized tribal governments)|Others(see text field entitled ""Additional Information on Eligibility"" for clarification)|Native American tribal governments(Federally recognized)"');
});

it('produces same number of rows as grid', async () => {
Expand Down
27 changes: 24 additions & 3 deletions packages/server/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,23 @@ function validateSearchFilters(filters) {
return errors;
}

function addCsvData(qb) {
qb
.select(knex.raw(`
CASE
WHEN grants.funding_instrument_codes = 'G' THEN 'Grant'
WHEN grants.funding_instrument_codes = 'CA' THEN 'Cooperative Agreement'
WHEN grants.funding_instrument_codes = 'PC' THEN 'Procurement Contract'
ELSE 'Other'
END as funding_type
`))
.select(knex.raw(`array_to_string(array_agg(${TABLES.eligibility_codes}.label), '|') AS eligibility`))
.leftJoin(
`${TABLES.eligibility_codes}`,
`${TABLES.eligibility_codes}.code`, '=', knex.raw(`ANY(string_to_array(${TABLES.grants}.eligibility_codes, ' '))`),
);
}

/*
filters: {
reviewStatuses: List[Enum['Applied', 'Not Applying', 'Interested']],
Expand All @@ -689,15 +706,15 @@ function validateSearchFilters(filters) {
tenantId: number
agencyId: number
*/
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId, agencyId) {
console.log(JSON.stringify([filters, paginationParams, orderingParams, tenantId, agencyId]));
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId, agencyId, toCsv) {
console.log(JSON.stringify([filters, paginationParams, orderingParams, tenantId, agencyId, toCsv]));

const errors = validateSearchFilters(filters);
if (errors.length > 0) {
throw new Error(`Invalid filters: ${errors.join(', ')}`);
}

const data = await knex(TABLES.grants)
const query = knex(TABLES.grants)
.select([
'grants.grant_id',
'grants.grant_number',
Expand Down Expand Up @@ -767,6 +784,10 @@ async function getGrantsNew(filters, paginationParams, orderingParams, tenantId,
'grants.funding_instrument_codes',
'grants.bill',
);
if (toCsv) {
query.modify(addCsvData);
}
const data = await query;

const fullCount = data.length > 0 ? data[0].full_count : 0;

Expand Down
1 change: 1 addition & 0 deletions packages/server/src/lib/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ async function getAndSendGrantForSavedSearch({
await db.buildPaginationParams({ currentPage: 1, perPage: 31 }),
{},
userSavedSearch.tenantId,
false,
);

return sendGrantDigest({
Expand Down
8 changes: 7 additions & 1 deletion packages/server/src/routes/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ router.get('/next', requireUser, async (req, res) => {
orderingParams,
user.tenant_id,
user.agency_id,
false,
);

return res.json(grants);
Expand Down Expand Up @@ -121,6 +122,7 @@ router.get('/exportCSVNew', requireUser, async (req, res) => {
orderingParams,
user.tenant_id,
user.agency_id,
true,
);

// Generate CSV
Expand Down Expand Up @@ -155,7 +157,7 @@ router.get('/exportCSVNew', requireUser, async (req, res) => {
{ key: 'title', header: 'Title' },
{ key: 'viewed_by', header: 'Viewed By' },
{ key: 'interested_agencies', header: 'Interested Teams' },
{ key: 'opportunity_status', header: 'Status' },
{ key: 'opportunity_status', header: 'Opportunity Status' },
{ key: 'opportunity_category', header: 'Opportunity Category' },
{ key: 'cost_sharing', header: 'Cost Sharing' },
{ key: 'award_ceiling', header: 'Award Ceiling' },
Expand All @@ -164,6 +166,10 @@ router.get('/exportCSVNew', requireUser, async (req, res) => {
{ key: 'agency_code', header: 'Agency Code' },
{ key: 'grant_id', header: 'Grant Id' },
{ key: 'url', header: 'URL' },
{ key: 'funding_type', header: 'Funding Type' },
{ key: 'bill', header: 'Appropriations Bill' },
{ key: 'agency_code', header: 'Agency Code' },
{ key: 'eligibility', header: 'Eligibility' },
],
});

Expand Down
39 changes: 20 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@
debug "^3.1.0"
lodash.once "^4.1.1"

"@datadog/native-appsec@^4.0.0":
"@datadog/[email protected]":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@datadog/native-appsec/-/native-appsec-4.0.0.tgz#ee08138b987dec557eac3650a43a972dac85b6a6"
integrity sha512-myTguXJ3VQHS2E1ylNsSF1avNpDmq5t+K4Q47wdzeakGc3sDIDDyEbvuFTujl9c9wBIkup94O1mZj5DR37ajzA==
Expand All @@ -2401,10 +2401,10 @@
lru-cache "^7.14.0"
node-gyp-build "^4.5.0"

"@datadog/[email protected].3":
version "1.6.3"
resolved "https://registry.yarnpkg.com/@datadog/native-iast-taint-tracking/-/native-iast-taint-tracking-1.6.3.tgz#cb2125f7bf18806da6f326c3a6b7210da3e05d8b"
integrity sha512-u/bBPNx0w8Bq+I+30enI99Ua2WPbVLkANGNyQNjW4tz2PHyeGI++HyzZV+fGm0YSy41FuHZq9EWP3SSDz/eSVw==
"@datadog/[email protected].4":
version "1.6.4"
resolved "https://registry.yarnpkg.com/@datadog/native-iast-taint-tracking/-/native-iast-taint-tracking-1.6.4.tgz#16c21ad7c36a53420c0d3c5a3720731809cc7e98"
integrity sha512-Owxk7hQ4Dxwv4zJAoMjRga0IvE6lhvxnNc8pJCHsemCWBXchjr/9bqg05Zy5JnMbKUWn4XuZeJD6RFZpRa8bfw==
dependencies:
node-gyp-build "^3.9.0"

Expand Down Expand Up @@ -6382,9 +6382,9 @@ core-js@^2.6.12:
integrity sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==

core-js@^3.21.1, core-js@^3.6.1, core-js@^3.8.3:
version "3.33.2"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.33.2.tgz#312bbf6996a3a517c04c99b9909cdd27138d1ceb"
integrity sha512-XeBzWI6QL3nJQiHmdzbAOiMYqjrb7hwU7A39Qhvd/POSa/t9E1AeZyEZx3fNvp/vtM8zXwhoL0FsiS0hD0pruQ==
version "3.33.3"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.33.3.tgz#3c644a323f0f533a0d360e9191e37f7fc059088d"
integrity sha512-lo0kOocUlLKmm6kv/FswQL8zbkH7mVsLJ/FULClOhv8WRVmKLVcs6XPNQAzstfeJTCHMyButEwG+z1kHxHoDZw==

[email protected]:
version "1.0.2"
Expand Down Expand Up @@ -6736,21 +6736,26 @@ dayjs@^1.10.4:
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.7.tgz#4b296922642f70999544d1144a2c25730fce63e2"
integrity sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==

dc-polyfill@^0.1.2:
version "0.1.3"
resolved "https://registry.yarnpkg.com/dc-polyfill/-/dc-polyfill-0.1.3.tgz#fe9eefc86813439dd46d6f9ad9582ec079c39720"
integrity sha512-Wyk5n/5KUj3GfVKV2jtDbtChC/Ff9fjKsBcg4ZtYW1yQe3DXNHcGURvmoxhqQdfOQ9TwyMjnfyv1lyYcOkFkFA==

dd-trace@^4.11.1:
version "4.18.0"
resolved "https://registry.yarnpkg.com/dd-trace/-/dd-trace-4.18.0.tgz#0c469c9d8df4b79cdfd1ef31db698532ee5e5815"
integrity sha512-rycfmSIshWcphYavFE4iozpu0QbnLpXiUuan+Ft3mvPFe+wYgqY8agu+goRNGAXZYFXNLk7jVN5OTXYO2AMJtQ==
version "4.20.0"
resolved "https://registry.yarnpkg.com/dd-trace/-/dd-trace-4.20.0.tgz#9a2cc3f28ff558c5605927b1362eb64605df76c1"
integrity sha512-y7IDLSSt6nww6zMdw/I8oLdfgOQADIOkERCNdfSzlBrXHz5CHimEOFfsHN87ag0mn6vusr06aoi+CQRZSNJz2g==
dependencies:
"@datadog/native-appsec" "^4.0.0"
"@datadog/native-appsec" "4.0.0"
"@datadog/native-iast-rewriter" "2.2.1"
"@datadog/native-iast-taint-tracking" "1.6.3"
"@datadog/native-iast-taint-tracking" "1.6.4"
"@datadog/native-metrics" "^2.0.0"
"@datadog/pprof" "4.0.1"
"@datadog/sketches-js" "^2.1.0"
"@opentelemetry/api" "^1.0.0"
"@opentelemetry/core" "^1.14.0"
crypto-randomuuid "^1.0.0"
diagnostics_channel "^1.1.0"
dc-polyfill "^0.1.2"
ignore "^5.2.4"
import-in-the-middle "^1.4.2"
int64-buffer "^0.1.9"
Expand All @@ -6770,6 +6775,7 @@ dd-trace@^4.11.1:
node-abort-controller "^3.1.1"
opentracing ">=0.12.1"
path-to-regexp "^0.1.2"
pprof-format "^2.0.7"
protobufjs "^7.2.4"
retry "^0.13.1"
semver "^7.5.4"
Expand Down Expand Up @@ -7068,11 +7074,6 @@ dezalgo@^1.0.4:
asap "^2.0.0"
wrappy "1"

diagnostics_channel@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/diagnostics_channel/-/diagnostics_channel-1.1.0.tgz#bd66c49124ce3bac697dff57466464487f57cea5"
integrity sha512-OE1ngLDjSBPG6Tx0YATELzYzy3RKHC+7veQ8gLa8yS7AAgw65mFbVdcsu3501abqOZCEZqZyAIemB0zXlqDSuw==

[email protected]:
version "5.0.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b"
Expand Down

0 comments on commit 3ae93db

Please sign in to comment.