[questions][chore] refactor question queries

pull/383/head
hpkoh 3 years ago
parent ff9cffa715
commit 6aec06ff00

@ -51,29 +51,34 @@ export const questionsQuestionRouter = createProtectedRouter()
},
}
: {}),
encounters : {
some: {
...(input.companies.length > 0
? {
company : {
in : input.companies
}
}
: {}),
...(input.locations.length > 0
? {
location: {
in: input.locations
},
}
: {}),
...(input.roles.length > 0
? {
role : {
in: input.roles
}
}
: {}),
}
}
},
});
return questionsData
.filter((data) => {
for (let i = 0; i < data.encounters.length; i++) {
const encounter = data.encounters[i];
const matchCompany =
input.companies.length === 0 ||
input.companies.includes(encounter.company);
const matchLocation =
input.locations.length === 0 ||
input.locations.includes(encounter.location);
const matchRole =
input.roles.length === 0 || input.roles.includes(encounter.role);
const matchDate =
(!input.startDate || encounter.seenAt >= input.startDate) &&
encounter.seenAt <= input.endDate;
if (matchCompany && matchLocation && matchRole && matchDate) {
return true;
}
}
return false;
})
.map((data) => {
const votes: number = data.votes.reduce(
(previousValue: number, currentValue) => {

Loading…
Cancel
Save