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

feat: CLIN-2365 fetch all filters by query return grouped by tag #65

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/routes/savedFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
updateAsDefault,
} from '../db/dal/savedFilter';
import {
formatByTag,
getFilterIDs,
handleUniqueName,
removeQueryFromFilters,
Expand Down Expand Up @@ -46,7 +47,7 @@ savedFiltersRouter.get('/', async (req, res, next) => {
}
res.status(StatusCodes.OK).send(updatedResults);
} else {
res.status(StatusCodes.OK).send(results);
res.status(StatusCodes.OK).send(formatByTag(results));
celinepelletier marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (e) {
next(e);
Expand Down
21 changes: 18 additions & 3 deletions src/utils/savedFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ const getCount = (filter) => {

return sequelizeConnection
.query(
`SELECT count(*) from saved_filters where keycloak_id = :keycloak_id and title = :title and type = :type and tag = :tag ${
filter.id ? 'and id <> :id' : ''
}`,
`SELECT count(*)
from saved_filters
where keycloak_id = :keycloak_id
and title = :title
and type = :type
and tag = :tag ${filter.id ? 'and id <> :id' : ''}`,
{
replacements,
type: QueryTypes.SELECT,
Expand Down Expand Up @@ -133,3 +136,15 @@ export const handleUniqueName = async (filter) => {
},
};
};

export const formatByTag = (queries) =>
queries.reduce((acc, query) => {
const { tag, ...rest } = query;

if (!acc[tag]) {
acc[tag] = [];
}

acc[tag].push(rest.dataValues);
return acc;
}, {});