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

#2856 - 500 error while filtering fix #2896

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions data-serving/data-service/src/controllers/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ export class CasesController {
searchQuery: req.body.query as string,
count: false,
limit: queryLimit,
}).cursor();
})
.collation({ locale: 'en_US', strength: 2 })
.cursor();
} else if (req.body.caseIds && queryLimit) {
logger.info('Request body with case IDs and limit');
cursor = Case.find({
Expand Down Expand Up @@ -210,7 +212,9 @@ export class CasesController {
}

const date = new Date().toISOString().slice(0, 10);
const request_description = req.body.query ? req.body.query.replace(/[:\s]/g, '_') : 'requested_cases';
const request_description = req.body.query
? req.body.query.replace(/[:\s]/g, '_')
: 'requested_cases';
const filename = `gh_${date}_${request_description}`;

let doc: CaseDocument;
Expand Down Expand Up @@ -341,14 +345,22 @@ export class CasesController {
const sortedQuery = casesQuery.sort({
[sortByKeyword]: sortByOrder === SortByOrder.Ascending ? 1 : -1,
});

// Do a fetch of documents and another fetch in parallel for total documents
// count used in pagination.
const [docs, total] = await Promise.all([
sortedQuery
.skip(limit * (page - 1))
.limit(limit)
.lean(),
countQuery,
.lean()
.collation({
locale: 'en_US',
strength: 2,
}),
countQuery.collation({
locale: 'en_US',
strength: 2,
}),
]);

const dtos = await Promise.all(docs.map(dtoFromCase));
Expand Down Expand Up @@ -807,7 +819,7 @@ export class CasesController {
const casesQuery = casesMatchingSearchQuery({
searchQuery: req.body.query,
count: false,
});
}).collation({ locale: 'en_US', strength: 2 });
try {
await Case.deleteMany(casesQuery);
await RestrictedCase.deleteMany(casesQuery);
Expand Down Expand Up @@ -867,7 +879,7 @@ export class CasesController {
updateQuery = casesMatchingSearchQuery({
searchQuery: req.body.query,
count: false,
});
}).collation({ locale: 'en_US', strength: 2 });
} else {
updateQuery = {
_id: { $in: caseIds },
Expand Down Expand Up @@ -1139,19 +1151,11 @@ export const casesMatchingSearchQuery = (opts: {
// Always search with case-insensitivity.
const casesQuery: Query<CaseDocument[], CaseDocument> = Case.find(
queryOpts,
).collation({
locale: 'en_US',
strength: 2,
});
);

const countQuery: Query<number, CaseDocument> = Case.countDocuments(
queryOpts,
)
.limit(countLimit)
.collation({
locale: 'en_US',
strength: 2,
});
).limit(countLimit);

// Fill in keyword filters.
parsedSearch.filters.forEach((f) => {
Expand Down Expand Up @@ -1348,8 +1352,14 @@ export const listOccupations = async (
}
};
function validateCaseAges(caseStart: number, caseEnd: number) {
if (caseStart < 0 || caseEnd < caseStart || caseStart > 120 || caseEnd > 120) {
throw new InvalidParamError(`Case validation failed: age range ${caseStart}-${caseEnd} invalid (must be within 0-120)`);
if (
caseStart < 0 ||
caseEnd < caseStart ||
caseStart > 120 ||
caseEnd > 120
) {
throw new InvalidParamError(
`Case validation failed: age range ${caseStart}-${caseEnd} invalid (must be within 0-120)`,
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,33 @@ const LinelistTable = () => {
return createData(
data._id || '',
renderDate(data.confirmationDate) || '',
data.location.administrativeAreaLevel3 || '',
data.location.administrativeAreaLevel2 || '',
data.location.administrativeAreaLevel1 || '',
nameCountry(data.location.country) || '',
parseFloat(data.location.geometry.latitude.toFixed(4)) || 0,
parseFloat(data.location.geometry.longitude.toFixed(4)) || 0,
data.location?.administrativeAreaLevel3 || '',
data.location?.administrativeAreaLevel2 || '',
data.location?.administrativeAreaLevel1 || '',
nameCountry(data.location?.country) || '',
parseFloat(data.location?.geometry.latitude.toFixed(4)) || 0,
parseFloat(data.location?.geometry.longitude.toFixed(4)) || 0,
data.demographics?.nationalities || '',
parseAge(
data.demographics?.ageRange?.start,
data.demographics?.ageRange?.end,
),
data.demographics?.gender || '',
data.importedCase?.outcome ||
data.events.find((event) => event.name === 'outcome')
data.events?.find((event) => event.name === 'outcome')
?.value ||
'',
renderDateRange(
data.events.find(
data.events?.find(
(event) => event.name === 'hospitalAdmission',
)?.dateRange,
),
renderDateRange(
data.events.find((event) => event.name === 'onsetSymptoms')
data.events?.find((event) => event.name === 'onsetSymptoms')
?.dateRange,
),
data.caseReference.sourceUrl || '',
data.caseReference.verificationStatus,
data.caseReference?.sourceUrl || '',
data.caseReference?.verificationStatus,
data.exclusionData,
);
});
Expand Down