Skip to content

Commit

Permalink
add query filter for route GET catalog => filterByKey and filterByValue
Browse files Browse the repository at this point in the history
  • Loading branch information
AmelieLoulergue committed Dec 18, 2024
1 parent e29539e commit 91d6808
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/api/controllers/catalog.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export const addFileInCatalog = async (req: Request, res: Response) => {

export const getFiles = async (req: Request, res: Response) => {
const { data: catalog } = await getCatalog();
return res.status(200).json(catalog);
if (req.query.filterByKey && req.query.filterByValue) {
return res.json(catalog.filter(item => item[`${req.query.filterByKey}`] === req.query.filterByValue))
}
return res.status(200).json(catalog)
};

export const getFile = async (req: Request, res: Response) => {
Expand Down

0 comments on commit 91d6808

Please sign in to comment.