From 8f40bd24641adae523661cf231f8dc7a305b142f Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Thu, 13 Jul 2023 15:32:47 +0200 Subject: [PATCH] refacto GET method with search param for deed types --- src/app/api/admin/DeedTypesController.ts | 13 +++++++++++++ src/app/api/super-admin/DeedTypesController.ts | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/app/api/admin/DeedTypesController.ts b/src/app/api/admin/DeedTypesController.ts index 742d55b4..dcdbb8cb 100644 --- a/src/app/api/admin/DeedTypesController.ts +++ b/src/app/api/admin/DeedTypesController.ts @@ -29,6 +29,19 @@ export default class DeedTypesController extends ApiController { if (req.query["q"]) { query = JSON.parse(req.query["q"] as string); } + + if (req.query["search"] && typeof req.query["search"] === "string") { + const filter = req.query["search"]; + query = { + where: { + name: { + contains: filter, + mode: "insensitive", + } + } + }; + } + const officeId: string = req.body.user.office_Id; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ; if(!query.where) query.where = { office: officeWhereInput}; diff --git a/src/app/api/super-admin/DeedTypesController.ts b/src/app/api/super-admin/DeedTypesController.ts index e2c8acba..0a499a8f 100644 --- a/src/app/api/super-admin/DeedTypesController.ts +++ b/src/app/api/super-admin/DeedTypesController.ts @@ -29,6 +29,19 @@ export default class DeedTypesController extends ApiController { if (req.query["q"]) { query = JSON.parse(req.query["q"] as string); } + + if (req.query["search"] && typeof req.query["search"] === "string") { + const filter = req.query["search"]; + query = { + where: { + name: { + contains: filter, + mode: "insensitive", + } + } + }; + } + const officeId: string = req.body.user.office_Id; const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ; if(!query.where) query.where = { office: officeWhereInput};