Skip to content

Commit

Permalink
fix: pagination and audit report (usdigitalresponse#1831)
Browse files Browse the repository at this point in the history
  • Loading branch information
as1729 authored and replicantSocks committed Sep 1, 2023
1 parent dabb1ba commit db6dfd2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 56 deletions.
13 changes: 10 additions & 3 deletions packages/client/src/components/GrantsTableNext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,17 @@
</b-row>
<b-row align-v="center">
<b-col cols="12" class="d-flex">
<b-pagination class="m-0" v-model="currentPage" :total-rows="totalRows" :per-page="perPage" first-number
last-number first-text="First" prev-text="Prev" next-text="Next" last-text="Last"
<b-pagination
class="m-0"
v-model="currentPage"
:total-rows="totalRows"
:per-page="perPage"
first-text="First"
prev-text="Prev"
next-text="Next"
last-text="Last"
aria-controls="grants-table" />
<div class="ml-2 border border-light rounded text-justify p-2 page-item">{{ grants.length }} of {{ totalRows }}</div>
<div class="ml-2 border border-light rounded text-justify p-2 page-item">{{ totalRows }} total grant{{ totalRows == 1 ? '' : 's' }}</div>
</b-col>
</b-row>
<GrantDetails :selected-grant.sync="selectedGrant" />
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/arpa_reporter/lib/audit-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async function generate(requestHost) {
XLSX.utils.book_append_sheet(newWorkbook, sheet1, 'Obligations & Expenditures');
XLSX.utils.book_append_sheet(newWorkbook, sheet2, 'Project Summaries');
XLSX.utils.book_append_sheet(newWorkbook, sheet3, 'Project Summaries V2');
XLSX.utils.book_append_sheet(workbook, sheet4, 'KPI');
XLSX.utils.book_append_sheet(newWorkbook, sheet4, 'KPI');
return newWorkbook;
});

Expand Down
62 changes: 10 additions & 52 deletions packages/server/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ function buildTsqExpression(includeKeywords, excludeKeywords) {
return keywords.expressions;
}

async function buildKeywordQuery(queryBuilder, includeKeywords, excludeKeywords) {
function buildKeywordQuery(queryBuilder, includeKeywords, excludeKeywords) {
const tsqExpression = buildTsqExpression(includeKeywords, excludeKeywords);
if (tsqExpression.phrase) {
queryBuilder.joinRaw(`cross join phraseto_tsquery('english', ?) as tsqp`, tsqExpression.phrase);
Expand All @@ -459,7 +459,7 @@ async function buildKeywordQuery(queryBuilder, includeKeywords, excludeKeywords)
}
}

async function buildFiltersQuery(queryBuilder, filters) {
function buildFiltersQuery(queryBuilder, filters, agencyId) {
const statusMap = {
Applied: 'Result',
'Not Applying': 'Rejected',
Expand All @@ -479,9 +479,9 @@ async function buildFiltersQuery(queryBuilder, filters) {
if (filters.reviewStatuses?.length) {
const statuses = filters.reviewStatuses.map((status) => statusMap[status]);
qb.whereIn(`${TABLES.interested_codes}.status_code`, statuses);
qb.where(`${TABLES.grants_interested}.agency_id`, '=', agencyId);
}
if (parseInt(filters.assignedToAgencyId, 10) >= 0) {
console.log(filters.assignedToAgencyId);
qb.where(`${TABLES.assigned_grants_agency}.agency_id`, '=', filters.assignedToAgencyId);
}
if (filters.opportunityStatuses?.length) {
Expand Down Expand Up @@ -524,15 +524,16 @@ async function buildFiltersQuery(queryBuilder, filters) {
bill: String,
},
paginationParams: { currentPage: number, perPage: number, isLengthAware: boolean },
orderingParams: { orderBy: List[string], orderDesc: boolean}
orderingParams: { orderBy: List[string], orderDesc: boolean},
tenantId: number
agencyId: number
*/
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId) {
console.log(filters, paginationParams, orderingParams, tenantId);
async function getGrantsNew(filters, paginationParams, orderingParams, tenantId, agencyId) {
console.log(filters, paginationParams, orderingParams, tenantId, agencyId);
const { data, pagination } = await knex(TABLES.grants)
.select(`${TABLES.grants}.*`)
.distinct()
.modify(async (queryBuilder) => {
.modify((queryBuilder) => {
if (filters) {
if (filters.reviewStatuses?.length) {
queryBuilder.join(TABLES.grants_interested, `${TABLES.grants}.grant_id`, `${TABLES.grants_interested}.grant_id`)
Expand All @@ -541,51 +542,8 @@ async function getGrantsNew(filters, paginationParams, orderingParams, tenantId)
if (parseInt(filters.assignedToAgencyId, 10) >= 0) {
queryBuilder.join(TABLES.assigned_grants_agency, `${TABLES.grants}.grant_id`, `${TABLES.assigned_grants_agency}.grant_id`);
}

<<<<<<< HEAD
/*
TODO: add grants.opportunity_number
if (filters.opportunityNumber) {
qb.where(`${TABLES.grants}.opportunity_number`, '=', filters.opportunityNumber);
}
TODO: add grants.funding_instrument_codes
{ 'CA': 'Cooperative Agreement', 'G': 'Grant', 'PC': 'Procurement Contract', 'O': 'Other' }
if (filters.fundingTypes) {
qb.where('funding_instrument_codes', '~', filters.fundingTypes.join('|'));
}
*/
if (filters.reviewStatuses?.length) {
for (const status in filters.reviewStatuses) {
qb.where(`${TABLES.interested_codes}.status_code`, '=', status);
}
}
if (filters.opportunityStatuses?.length) {
qb.whereIn(`${TABLES.grants}.opportunity_status`, filters.opportunityStatuses);
}
if (filters.opportunityCategories?.length) {
qb.whereIn(`${TABLES.grants}.opportunity_category`, filters.opportunityCategories);
}
if (filters.costSharing) {
qb.where(`${TABLES.grants}.cost_sharing`, '=', filters.costSharing);
}
if (filters.agencyCode) {
qb.where(`${TABLES.grants}.agency_code`, '=', filters.agencyCode);
}
if (filters.openDate) {
qb.where(`${TABLES.grants}.open_date`, '=', filters.openDate);
} else if (filters.postedWithinDays > 0) {
const date = moment().subtract(filters.postedWithinDays, 'days').startOf('day').format('YYYY-MM-DD');
qb.where(`${TABLES.grants}.open_date`, '>=', date);
}
},
);
=======
await buildKeywordQuery(queryBuilder, filters.includeKeywords, filters.excludeKeywords);
console.log('here 1');
await buildFiltersQuery(queryBuilder, filters);
console.log('here 2');
>>>>>>> 1f415725 (fix: initial search adjustments 815 review (#1826))
buildKeywordQuery(queryBuilder, filters.includeKeywords, filters.excludeKeywords);
buildFiltersQuery(queryBuilder, filters, agencyId);
}
if (orderingParams.orderBy && orderingParams.orderBy !== 'undefined') {
if (orderingParams.orderBy.includes('interested_agencies')) {
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/routes/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ router.get('/next', requireUser, async (req, res) => {
await db.buildPaginationParams(req.query.pagination),
await db.buildOrderingParams(req.query.ordering),
user.tenant_id,
user.agency_id,
);

res.json(grants);
Expand Down

0 comments on commit db6dfd2

Please sign in to comment.