From 23ba2672dd68fb00f866dc4c02d7eb200b53169c Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Mon, 9 Oct 2023 12:02:28 +0200 Subject: [PATCH] refacto GET officeFolder for admin & super-admin --- src/app/api/admin/OfficeFoldersController.ts | 8 ++++---- .../super-admin/OfficeFoldersController.ts | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/app/api/admin/OfficeFoldersController.ts b/src/app/api/admin/OfficeFoldersController.ts index 42fbdc58..bf1c8732 100644 --- a/src/app/api/admin/OfficeFoldersController.ts +++ b/src/app/api/admin/OfficeFoldersController.ts @@ -58,10 +58,10 @@ export default class OfficeFoldersController extends ApiController { }; } - const officeId: string = req.body.user.office_Id; - const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ; - if(!query.where) query.where = { office: officeWhereInput}; - query.where.office = officeWhereInput; + const userId: string = req.body.user.userId; + if (query.where?.stakeholders) delete query.where.stakeholders; + const officeFoldersWhereInput: Prisma.OfficeFoldersWhereInput = { ...query.where, stakeholders: { some: { uid: userId } } }; + query.where = officeFoldersWhereInput; //call service to get prisma entity const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query); diff --git a/src/app/api/super-admin/OfficeFoldersController.ts b/src/app/api/super-admin/OfficeFoldersController.ts index e0b01345..f31d2807 100644 --- a/src/app/api/super-admin/OfficeFoldersController.ts +++ b/src/app/api/super-admin/OfficeFoldersController.ts @@ -44,12 +44,10 @@ export default class OfficeFoldersController extends ApiController { { customers: { some: { - contact: { - OR: [ - { first_name: { contains: filter, mode: "insensitive" } }, - { last_name: { contains: filter, mode: "insensitive" } }, - ], - }, + OR: [ + { contact: { first_name: { contains: filter, mode: "insensitive" } } }, + { contact: { last_name: { contains: filter, mode: "insensitive" } } }, + ], }, }, }, @@ -57,10 +55,11 @@ export default class OfficeFoldersController extends ApiController { }, }; } - const officeId: string = req.body.user.office_Id; - const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId }; - if (!query.where) query.where = { office: officeWhereInput }; - query.where.office = officeWhereInput; + + const userId: string = req.body.user.userId; + if (query.where?.stakeholders) delete query.where.stakeholders; + const officeFoldersWhereInput: Prisma.OfficeFoldersWhereInput = { ...query.where, stakeholders: { some: { uid: userId } } }; + query.where = officeFoldersWhereInput; //call service to get prisma entity const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);