From 5f6100b0bb393adc943485ae663e0ca6e5c5ac18 Mon Sep 17 00:00:00 2001 From: m5r Date: Thu, 21 Oct 2021 00:24:18 +0200 Subject: [PATCH] prepare multiple phone numbers in one account --- app/auth/mutations/login.ts | 6 +----- app/messages/mutations/send-message.ts | 2 +- app/messages/queries/get-conversations.ts | 2 +- app/phone-calls/api/webhook/call.ts | 1 + app/phone-numbers/queries/get-current-phone-number.ts | 1 + 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/auth/mutations/login.ts b/app/auth/mutations/login.ts index 5afb76d..7252714 100644 --- a/app/auth/mutations/login.ts +++ b/app/auth/mutations/login.ts @@ -10,11 +10,7 @@ export const authenticateUser = async (rawEmail: string, rawPassword: string) => where: { email }, include: { memberships: { - include: { - organization: { - include: { phoneNumbers: true }, - }, - }, + include: { organization: true }, }, }, }); diff --git a/app/messages/mutations/send-message.ts b/app/messages/mutations/send-message.ts index be3b0a5..59c512a 100644 --- a/app/messages/mutations/send-message.ts +++ b/app/messages/mutations/send-message.ts @@ -32,7 +32,7 @@ export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ return; } - const phoneNumber = organization.phoneNumbers[0]; + const phoneNumber = organization.phoneNumbers[0]; // TODO: use the active number, not the first one if (!phoneNumber) { throw new NotFoundError(); } diff --git a/app/messages/queries/get-conversations.ts b/app/messages/queries/get-conversations.ts index b9650f4..eda5fde 100644 --- a/app/messages/queries/get-conversations.ts +++ b/app/messages/queries/get-conversations.ts @@ -26,7 +26,7 @@ export default resolver.pipe( throw new NotFoundError(); } - const phoneNumberId = organization.phoneNumbers[0].id; + const phoneNumberId = organization.phoneNumbers[0].id; // TODO: use the active number, not the first one const processingState = await db.processingPhoneNumber.findFirst({ where: { organizationId, phoneNumberId } }); if (processingState && !processingState.hasFetchedMessages) { return; diff --git a/app/phone-calls/api/webhook/call.ts b/app/phone-calls/api/webhook/call.ts index ca2b506..11dc4b8 100644 --- a/app/phone-calls/api/webhook/call.ts +++ b/app/phone-calls/api/webhook/call.ts @@ -30,6 +30,7 @@ export default async function incomingCallHandler(req: BlitzApiRequest, res: Bli const recipient = req.body.To; const organizationId = req.body.From.slice("client:".length).split("__")[0]; const phoneNumber = await db.phoneNumber.findFirst({ + // TODO: use the active number, not the first one where: { organizationId }, include: { organization: { diff --git a/app/phone-numbers/queries/get-current-phone-number.ts b/app/phone-numbers/queries/get-current-phone-number.ts index 1762491..b1c9462 100644 --- a/app/phone-numbers/queries/get-current-phone-number.ts +++ b/app/phone-numbers/queries/get-current-phone-number.ts @@ -11,6 +11,7 @@ export default resolver.pipe( enforceSuperAdminIfNotCurrentOrganization, async ({ organizationId }) => { return db.phoneNumber.findFirst({ + // TODO: use the active number, not the first one where: { organizationId }, select: { id: true,