From a693c560ff79e96e10962357b6fac66c257a2b82 Mon Sep 17 00:00:00 2001 From: meek0 Date: Wed, 2 Oct 2024 10:57:56 -0400 Subject: [PATCH] fix: CLIN-3242 use unique_id url param to filter flags --- src/db/dal/variant.ts | 6 ++++-- src/routes/variant.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/db/dal/variant.ts b/src/db/dal/variant.ts index 28c1ca5..1192dd0 100644 --- a/src/db/dal/variant.ts +++ b/src/db/dal/variant.ts @@ -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 ( @@ -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 ')});`); diff --git a/src/routes/variant.ts b/src/routes/variant.ts index 3026712..13040d9 100644 --- a/src/routes/variant.ts +++ b/src/routes/variant.ts @@ -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);