From 7a4c583ea52e092a1f8181533a505ee08dcffc96 Mon Sep 17 00:00:00 2001 From: m5r Date: Wed, 20 Oct 2021 23:57:32 +0200 Subject: [PATCH] fetch phone number data even if user is not on a paid plan --- .../api/queue/subscription-created.ts | 25 ---------- app/settings/mutations/set-phone-number.ts | 48 ++++++++----------- 2 files changed, 20 insertions(+), 53 deletions(-) diff --git a/app/settings/api/queue/subscription-created.ts b/app/settings/api/queue/subscription-created.ts index 6743872..c69a245 100644 --- a/app/settings/api/queue/subscription-created.ts +++ b/app/settings/api/queue/subscription-created.ts @@ -7,8 +7,6 @@ import appLogger from "integrations/logger"; import { sendEmail } from "integrations/aws-ses"; import type { Metadata } from "integrations/paddle"; import { translateSubscriptionStatus } from "integrations/paddle"; -import fetchMessagesQueue from "../../../messages/api/queue/fetch-messages"; -import fetchCallsQueue from "../../../phone-calls/api/queue/fetch-calls"; const logger = appLogger.child({ queue: "subscription-created" }); @@ -51,29 +49,6 @@ export const subscriptionCreatedQueue = Queue("api/queue/subscription-c }, }); - const phoneNumber = organization.phoneNumbers[0]; - if (phoneNumber) { - const phoneNumberId = phoneNumber.id; - await Promise.all([ - db.processingPhoneNumber.create({ - data: { - organizationId, - phoneNumberId, - hasFetchedMessages: false, - hasFetchedCalls: false, - }, - }), - fetchMessagesQueue.enqueue( - { organizationId, phoneNumberId }, - { id: `fetch-messages-${organizationId}-${phoneNumberId}` }, - ), - fetchCallsQueue.enqueue( - { organizationId, phoneNumberId }, - { id: `fetch-messages-${organizationId}-${phoneNumberId}` }, - ), - ]); - } - if (isReturningSubscriber) { sendEmail({ subject: "Welcome back to Shellphone", diff --git a/app/settings/mutations/set-phone-number.ts b/app/settings/mutations/set-phone-number.ts index 1baa7de..9e03fbe 100644 --- a/app/settings/mutations/set-phone-number.ts +++ b/app/settings/mutations/set-phone-number.ts @@ -6,8 +6,8 @@ import RestException from "twilio/lib/base/RestException"; import db from "db"; import getCurrentUser from "app/users/queries/get-current-user"; import setTwilioWebhooks from "../api/queue/set-twilio-webhooks"; -import fetchMessagesQueue from "../../messages/api/queue/fetch-messages"; -import fetchCallsQueue from "../../phone-calls/api/queue/fetch-calls"; +import fetchMessagesQueue from "app/messages/api/queue/fetch-messages"; +import fetchCallsQueue from "app/phone-calls/api/queue/fetch-calls"; const Body = z.object({ phoneNumberSid: z.string(), @@ -81,34 +81,26 @@ export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ } const phoneNumberId = phoneNumberSid; - let promises: Promise[] = [ + await Promise.all([ setTwilioWebhooks.enqueue( { organizationId, phoneNumberId }, { id: `set-twilio-webhooks-${organizationId}-${phoneNumberId}` }, ), - ]; - - const hasActiveSubscription = organization.subscriptions.length > 0; - if (hasActiveSubscription) { - promises.push( - db.processingPhoneNumber.create({ - data: { - organizationId, - phoneNumberId, - hasFetchedMessages: false, - hasFetchedCalls: false, - }, - }), - fetchMessagesQueue.enqueue( - { organizationId, phoneNumberId }, - { id: `fetch-messages-${organizationId}-${phoneNumberId}` }, - ), - fetchCallsQueue.enqueue( - { organizationId, phoneNumberId }, - { id: `fetch-messages-${organizationId}-${phoneNumberId}` }, - ), - ); - } - - await Promise.all(promises); + db.processingPhoneNumber.create({ + data: { + organizationId, + phoneNumberId, + hasFetchedMessages: false, + hasFetchedCalls: false, + }, + }), + fetchMessagesQueue.enqueue( + { organizationId, phoneNumberId }, + { id: `fetch-messages-${organizationId}-${phoneNumberId}` }, + ), + fetchCallsQueue.enqueue( + { organizationId, phoneNumberId }, + { id: `fetch-messages-${organizationId}-${phoneNumberId}` }, + ), + ]); });