From 433d553cec9192bac1d2c153df6d43a0b0563893 Mon Sep 17 00:00:00 2001 From: Joe Karow <58997957+JoeKarow@users.noreply.github.com> Date: Tue, 20 Feb 2024 17:40:59 -0500 Subject: [PATCH] fix isSingleLoc filtering --- .../orgPhone/query.forContactInfo.handler.ts | 4 ++-- .../query.forContactInfo.handler.ts | 4 ++-- .../query.forContactInfo.handler.ts | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/api/router/orgPhone/query.forContactInfo.handler.ts b/packages/api/router/orgPhone/query.forContactInfo.handler.ts index c29d30bc335..a2f57545ed8 100644 --- a/packages/api/router/orgPhone/query.forContactInfo.handler.ts +++ b/packages/api/router/orgPhone/query.forContactInfo.handler.ts @@ -9,13 +9,13 @@ const getWhereId = (input: TForContactInfoSchema, isSingleLoc?: boolean): Prisma switch (true) { case isIdFor('organization', input.parentId): { return isSingleLoc - ? { + ? { organization: { organization: { id: input.parentId, ...isPublic } } } + : { OR: [ { organization: { organization: { id: input.parentId, ...isPublic } } }, { locations: { some: { location: { organization: { id: input.parentId, ...isPublic } } } } }, ], } - : { organization: { organization: { id: input.parentId, ...isPublic } } } } case isIdFor('orgLocation', input.parentId): { return { locations: { some: { location: { id: input.parentId, ...isPublic } } } } diff --git a/packages/api/router/orgSocialMedia/query.forContactInfo.handler.ts b/packages/api/router/orgSocialMedia/query.forContactInfo.handler.ts index f2213734df5..2b8d0868ce5 100644 --- a/packages/api/router/orgSocialMedia/query.forContactInfo.handler.ts +++ b/packages/api/router/orgSocialMedia/query.forContactInfo.handler.ts @@ -9,13 +9,13 @@ const whereId = (input: TForContactInfoSchema, isSingleLoc?: boolean): Prisma.Or switch (true) { case isIdFor('organization', input.parentId): { return isSingleLoc - ? { + ? { organization: { id: input.parentId, ...isPublic } } + : { OR: [ { organization: { id: input.parentId, ...isPublic } }, { locations: { every: { location: { organization: { id: input.parentId, ...isPublic } } } } }, ], } - : { organization: { id: input.parentId, ...isPublic } } } case isIdFor('orgLocation', input.parentId): { return { locations: { some: { location: { id: input.parentId, ...isPublic } } } } diff --git a/packages/api/router/orgWebsite/query.forContactInfo.handler.ts b/packages/api/router/orgWebsite/query.forContactInfo.handler.ts index 45edbfc9b09..98351ef8cb9 100644 --- a/packages/api/router/orgWebsite/query.forContactInfo.handler.ts +++ b/packages/api/router/orgWebsite/query.forContactInfo.handler.ts @@ -10,16 +10,16 @@ const whereId = (input: TForContactInfoSchema, isSingleLoc?: boolean): Prisma.Or switch (true) { case isIdFor('organization', input.parentId): { return isSingleLoc - ? { + ? { organization: { id: input.parentId, ...isPublic } } + : { OR: [ { organization: { id: input.parentId, ...isPublic } }, { locations: { every: { location: { organization: { id: input.parentId, ...isPublic } } } } }, ], } - : { organization: { id: input.parentId, ...isPublic } } } case isIdFor('orgLocation', input.parentId): { - return { locations: { some: { location: { id: input.parentId, ...isPublic } } } } + return { locations: { every: { location: { id: input.parentId, ...isPublic } } } } } default: { @@ -35,13 +35,16 @@ export const forContactInfo = async ({ input }: TRPCHandlerParams