fetch messages when switching to free plan
This commit is contained in:
parent
526ab4e451
commit
dad61ae77e
@ -4,8 +4,6 @@ import twilio from "twilio";
|
||||
|
||||
import db from "../../../db";
|
||||
import getCurrentUser from "../../users/queries/get-current-user";
|
||||
import fetchMessagesQueue from "../../messages/api/queue/fetch-messages";
|
||||
import fetchCallsQueue from "../../phone-calls/api/queue/fetch-calls";
|
||||
import setTwilioWebhooks from "../api/queue/set-twilio-webhooks";
|
||||
|
||||
const Body = z.object({
|
||||
@ -46,22 +44,6 @@ export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({
|
||||
|
||||
const phoneNumberId = phoneNumberSid;
|
||||
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}` },
|
||||
),
|
||||
setTwilioWebhooks.enqueue(
|
||||
{ organizationId, phoneNumberId },
|
||||
{ id: `set-twilio-webhooks-${organizationId}-${phoneNumberId}` },
|
||||
|
@ -7,6 +7,9 @@ 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";
|
||||
import setTwilioWebhooks from "../../../onboarding/api/queue/set-twilio-webhooks";
|
||||
|
||||
const logger = appLogger.child({ queue: "subscription-created" });
|
||||
|
||||
@ -19,6 +22,7 @@ export const subscriptionCreatedQueue = Queue<Payload>("api/queue/subscription-c
|
||||
const organization = await db.organization.findFirst({
|
||||
where: { id: organizationId },
|
||||
include: {
|
||||
phoneNumbers: true,
|
||||
subscriptions: true,
|
||||
memberships: {
|
||||
include: { user: true },
|
||||
@ -48,6 +52,30 @@ export const subscriptionCreatedQueue = Queue<Payload>("api/queue/subscription-c
|
||||
},
|
||||
});
|
||||
|
||||
const phoneNumberId = organization.phoneNumbers[0]!.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}` },
|
||||
),
|
||||
setTwilioWebhooks.enqueue(
|
||||
{ organizationId, phoneNumberId },
|
||||
{ id: `set-twilio-webhooks-${organizationId}-${phoneNumberId}` },
|
||||
),
|
||||
]);
|
||||
|
||||
if (isReturningSubscriber) {
|
||||
sendEmail({
|
||||
subject: "Welcome back to Shellphone",
|
||||
|
Loading…
Reference in New Issue
Block a user