From c1f878cdb2deeb6fe013d6c7cc833dd15d9597a8 Mon Sep 17 00:00:00 2001 From: Frederik Batuna Date: Wed, 30 Oct 2024 18:39:47 +0100 Subject: [PATCH] add: cgn partner search endpoint --- src/routers/features/cgn/merchants.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/routers/features/cgn/merchants.ts b/src/routers/features/cgn/merchants.ts index 6c57dd0f..e7924bce 100644 --- a/src/routers/features/cgn/merchants.ts +++ b/src/routers/features/cgn/merchants.ts @@ -22,6 +22,7 @@ import { addHandler } from "../../../payloads/response"; import { sendFileFromRootPath } from "../../../utils/file"; import { addApiV1Prefix } from "../../../utils/strings"; import { publicRouter } from "../../public"; +import { SearchRequest } from "../../../../generated/definitions/cgn/merchants/SearchRequest"; export const cgnMerchantsRouter = Router(); @@ -74,6 +75,28 @@ addHandler( } ); +addHandler(cgnMerchantsRouter, "post", addPrefix("/search"), (req, res) => { + if (SearchRequest.is(req.body)) { + return res.status(200).json({ + items: merchantsAll + .filter( + merchant => + merchant.name.toLowerCase().includes(req.body.token.toLowerCase()) || + merchant.description + ?.toLowerCase() + .includes(req.body.token.toLowerCase()) + ) + .map(merchant => ({ + id: merchant.id, + name: merchant.name, + description: merchant.description, + newDiscounts: faker.datatype.boolean() + })) + }); + } + return res.status(500); +}); + addHandler( cgnMerchantsRouter, "post",