Skip to content

Commit

Permalink
fix: CLIN-3242 use unique_id url param to filter flags
Browse files Browse the repository at this point in the history
  • Loading branch information
meek0 committed Oct 2, 2024
1 parent 7ab2183 commit a693c56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/db/dal/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ export const getEntriesByUniqueIdsAndOrganizations = async function (uniqueIds:
});
}

export const getEntriesByPropertiesFlags = async function (flags: string[], organizationIds: string[]) {
export const getEntriesByPropertiesFlags = async function (flags: string[], organizationIds: string[], uniqueIdParam: string) {
const flagsWhere = flags.map(f => {
return `properties @> '{"flags": ["${f}"]}'`;
});

const uniqueIdWhere = uniqueIdParam.length > 0 ? ` AND unique_id LIKE '%${uniqueIdParam}%'` : '';

const result = await VariantModel.sequelize.query(`
SELECT unique_id, timestamp, properties, rnk
FROM (
Expand All @@ -39,7 +41,7 @@ export const getEntriesByPropertiesFlags = async function (flags: string[], orga
properties,
RANK() OVER (PARTITION BY unique_id ORDER BY timestamp DESC) AS rnk
FROM variants
WHERE organization_id IN ('${organizationIds.join("', '")}')
WHERE organization_id IN ('${organizationIds.join("', '")}') ${uniqueIdWhere}
) s
WHERE rnk = 1 AND (${flagsWhere.join(' OR ')});`);

Expand Down
4 changes: 3 additions & 1 deletion src/routes/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ variantRouter.get('/filter', async (req, res, next) => {
flags.push(flagsParam);
}

let uniqueIdFilterParam = (req.query?.unique_id || '').toString().trim();

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

0 comments on commit a693c56

Please sign in to comment.