fetch phone number data even if user is not on a paid plan

This commit is contained in:
m5r 2021-10-20 23:57:32 +02:00
parent 5df0634060
commit 7a4c583ea5
2 changed files with 20 additions and 53 deletions

View File

@ -7,8 +7,6 @@ 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 "../../../messages/api/queue/fetch-messages";
import fetchCallsQueue from "../../../phone-calls/api/queue/fetch-calls";
const logger = appLogger.child({ queue: "subscription-created" }); const logger = appLogger.child({ queue: "subscription-created" });
@ -51,29 +49,6 @@ export const subscriptionCreatedQueue = Queue<Payload>("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) { if (isReturningSubscriber) {
sendEmail({ sendEmail({
subject: "Welcome back to Shellphone", subject: "Welcome back to Shellphone",

View File

@ -6,8 +6,8 @@ import RestException from "twilio/lib/base/RestException";
import db from "db"; import db from "db";
import getCurrentUser from "app/users/queries/get-current-user"; import getCurrentUser from "app/users/queries/get-current-user";
import setTwilioWebhooks from "../api/queue/set-twilio-webhooks"; import setTwilioWebhooks from "../api/queue/set-twilio-webhooks";
import fetchMessagesQueue from "../../messages/api/queue/fetch-messages"; import fetchMessagesQueue from "app/messages/api/queue/fetch-messages";
import fetchCallsQueue from "../../phone-calls/api/queue/fetch-calls"; import fetchCallsQueue from "app/phone-calls/api/queue/fetch-calls";
const Body = z.object({ const Body = z.object({
phoneNumberSid: z.string(), phoneNumberSid: z.string(),
@ -81,34 +81,26 @@ export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({
} }
const phoneNumberId = phoneNumberSid; const phoneNumberId = phoneNumberSid;
let promises: Promise<any>[] = [ await Promise.all([
setTwilioWebhooks.enqueue( setTwilioWebhooks.enqueue(
{ organizationId, phoneNumberId }, { organizationId, phoneNumberId },
{ id: `set-twilio-webhooks-${organizationId}-${phoneNumberId}` }, { id: `set-twilio-webhooks-${organizationId}-${phoneNumberId}` },
), ),
]; db.processingPhoneNumber.create({
data: {
const hasActiveSubscription = organization.subscriptions.length > 0; organizationId,
if (hasActiveSubscription) { phoneNumberId,
promises.push( hasFetchedMessages: false,
db.processingPhoneNumber.create({ hasFetchedCalls: false,
data: { },
organizationId, }),
phoneNumberId, fetchMessagesQueue.enqueue(
hasFetchedMessages: false, { organizationId, phoneNumberId },
hasFetchedCalls: false, { id: `fetch-messages-${organizationId}-${phoneNumberId}` },
}, ),
}), fetchCallsQueue.enqueue(
fetchMessagesQueue.enqueue( { organizationId, phoneNumberId },
{ organizationId, phoneNumberId }, { id: `fetch-messages-${organizationId}-${phoneNumberId}` },
{ id: `fetch-messages-${organizationId}-${phoneNumberId}` }, ),
), ]);
fetchCallsQueue.enqueue(
{ organizationId, phoneNumberId },
{ id: `fetch-messages-${organizationId}-${phoneNumberId}` },
),
);
}
await Promise.all(promises);
}); });