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

refactor: extract filter values into variables #121

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ export class GLASSDataSubmissionDefaultRepository implements GLASSDataSubmission
const amrIndividualModule = modules.find(module => module.name === "AMR - Individual")?.id;
const egaspModule = modules.find(module => module.name === "EGASP")?.id;

if (module === "AMR") return object.module === amrModule;
else if (module === "AMRIndividual") return object.module === amrIndividualModule;
else if (module === "EGASP") return object.module === egaspModule;
else return [];
return (
(module === "AMR" && object.module === amrModule) ||
(module === "AMRIndividual" && object.module === amrIndividualModule) ||
(module === "EGASP" && object.module === egaspModule)
);
}) ?? [];

const uploads =
Expand Down Expand Up @@ -185,13 +186,18 @@ export class GLASSDataSubmissionDefaultRepository implements GLASSDataSubmission
const quarterPeriods = _.flatMap(periods, year => quarters.map(quarter => `${year}${quarter}`));

const filteredRows = rows.filter(row => {
const isInFilteredOUs = _.isEmpty(orgUnitIds) || !row.orgUnit ? true : orgUnitIds.includes(row.orgUnit);
const isInFilteredPeriods = periods.includes(String(row.period));
const isInFilteredQuarterPeriods = quarterPeriods.includes(String(row.period));
const isFilteredCompletionStatus =
completionStatus !== undefined ? row.questionnaireCompleted === completionStatus : true;
const isFilteredSubmissionStatus = !submissionStatus ? true : row.status === submissionStatus;

return (
(_.isEmpty(orgUnitIds) || !row.orgUnit ? row : orgUnitIds.includes(row.orgUnit)) &&
(dataSubmissionPeriod === "YEARLY"
? periods.includes(String(row.period))
: quarterPeriods.includes(String(row.period))) &&
(completionStatus !== undefined ? row.questionnaireCompleted === completionStatus : row) &&
(!submissionStatus ? row : row.status === submissionStatus)
isInFilteredOUs &&
((dataSubmissionPeriod === "YEARLY" ? isInFilteredPeriods : isInFilteredQuarterPeriods) &&
isFilteredCompletionStatus &&
isFilteredSubmissionStatus
);
});

Expand Down Expand Up @@ -243,13 +249,15 @@ export class GLASSDataSubmissionDefaultRepository implements GLASSDataSubmission

const filteredRows = rows
.filter(row => {
return (
(_.isEmpty(orgUnitIds) || !row.orgUnit ? row : orgUnitIds.includes(row.orgUnit.id)) &&
!!(!from && !to
? row
: (from && new Date(row.creationDate) >= from) || (to && new Date(row.creationDate) <= to)) &&
(!submissionStatus ? row : row.status === submissionStatus)
);
const isInFilteredOUs =
_.isEmpty(orgUnitIds) || !row.orgUnit ? true : orgUnitIds.includes(row.orgUnit.id);
const isFilteredSubmissionStatus = !submissionStatus ? true : row.status === submissionStatus;
const isBetweenFilteredDuration =
!from && !to
? true
: (from && new Date(row.creationDate) >= from) || (to && new Date(row.creationDate) <= to);

return isInFilteredOUs && isBetweenFilteredDuration && isFilteredSubmissionStatus;
})
.map(row => {
const submissionStatus = earStatusItems.find(item => item.value === row.status)?.text ?? "";
Expand Down