From 950a7e1bd04ae643ab856dcd64f3d2ae3604bd6f Mon Sep 17 00:00:00 2001 From: m5r Date: Thu, 21 Oct 2021 00:39:09 +0200 Subject: [PATCH] fetch dismissed messages and phone calls that might have happened while on free plan --- .../api/queue/subscription-created.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/settings/api/queue/subscription-created.ts b/app/settings/api/queue/subscription-created.ts index c69a245..0fef655 100644 --- a/app/settings/api/queue/subscription-created.ts +++ b/app/settings/api/queue/subscription-created.ts @@ -7,6 +7,8 @@ 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 "app/messages/api/queue/fetch-messages"; +import fetchCallsQueue from "app/phone-calls/api/queue/fetch-calls"; const logger = appLogger.child({ queue: "subscription-created" }); @@ -49,6 +51,30 @@ export const subscriptionCreatedQueue = Queue("api/queue/subscription-c }, }); + // fetch dismissed messages and phone calls that might have happened while on free plan + 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",