fetch dismissed messages and phone calls that might have happened while on free plan

This commit is contained in:
m5r 2021-10-21 00:39:09 +02:00
parent a4859137fe
commit 950a7e1bd0

View File

@ -7,6 +7,8 @@ import appLogger from "integrations/logger";
import { sendEmail } from "integrations/aws-ses"; import { sendEmail } from "integrations/aws-ses";
import type { Metadata } from "integrations/paddle"; import type { Metadata } from "integrations/paddle";
import { translateSubscriptionStatus } 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" }); const logger = appLogger.child({ queue: "subscription-created" });
@ -49,6 +51,30 @@ export const subscriptionCreatedQueue = Queue<Payload>("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) { if (isReturningSubscriber) {
sendEmail({ sendEmail({
subject: "Welcome back to Shellphone", subject: "Welcome back to Shellphone",