Skip to content

Commit

Permalink
Merge pull request #94 from Ferlab-Ste-Justine/fix/clin-3242
Browse files Browse the repository at this point in the history
fix: CLIN-3242 fix search by flag
  • Loading branch information
meek0 authored Oct 2, 2024
2 parents 2c37eb0 + fbeb369 commit 7ab2183
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions src/db/dal/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ export const getEntriesByUniqueIdsAndOrganizations = async function (uniqueIds:
}

export const getEntriesByPropertiesFlags = async function (flags: string[], organizationIds: string[]) {
return await VariantModel.findAll({
attributes: ['unique_id'],
group: ['unique_id'],
where: {
[Op.or]: flags.map(f => {
return {
properties: {
[Op.contains]: {
flags: [f]
}
}
};
}),
organization_id: {
[Op.in]: organizationIds
}
}
const flagsWhere = flags.map(f => {
return `properties @> '{"flags": ["${f}"]}'`;
});

const result = await VariantModel.sequelize.query(`
SELECT unique_id, timestamp, properties, rnk
FROM (
SELECT
unique_id,
timestamp,
properties,
RANK() OVER (PARTITION BY unique_id ORDER BY timestamp DESC) AS rnk
FROM variants
WHERE organization_id IN ('${organizationIds.join("', '")}')
) s
WHERE rnk = 1 AND (${flagsWhere.join(' OR ')});`);

return result;
}
2 changes: 1 addition & 1 deletion src/routes/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ variantRouter.get('/filter', async (req, res, next) => {

if (canGet && flags.length > 0) {
dbResponse = await getEntriesByPropertiesFlags(flags, userInfo.userOrganizations);
return res.status(StatusCodes.OK).send(dbResponse.map(r => r.unique_id));
return res.status(StatusCodes.OK).send(dbResponse[0].map(r => r.unique_id));
} else if (!canGet) {
return res.sendStatus(StatusCodes.FORBIDDEN);
} else {
Expand Down

0 comments on commit 7ab2183

Please sign in to comment.