fetch phone number data even if user is not on a paid plan
This commit is contained in:
parent
5df0634060
commit
7a4c583ea5
@ -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",
|
||||||
|
@ -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,16 +81,11 @@ 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}` },
|
||||||
),
|
),
|
||||||
];
|
|
||||||
|
|
||||||
const hasActiveSubscription = organization.subscriptions.length > 0;
|
|
||||||
if (hasActiveSubscription) {
|
|
||||||
promises.push(
|
|
||||||
db.processingPhoneNumber.create({
|
db.processingPhoneNumber.create({
|
||||||
data: {
|
data: {
|
||||||
organizationId,
|
organizationId,
|
||||||
@ -107,8 +102,5 @@ export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({
|
|||||||
{ organizationId, phoneNumberId },
|
{ organizationId, phoneNumberId },
|
||||||
{ id: `fetch-messages-${organizationId}-${phoneNumberId}` },
|
{ id: `fetch-messages-${organizationId}-${phoneNumberId}` },
|
||||||
),
|
),
|
||||||
);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user