smol fixes to subscription webhooks

This commit is contained in:
m5r 2021-10-20 19:25:07 +02:00
parent 4096cfaa6c
commit 4ce3c2503a
2 changed files with 24 additions and 22 deletions

View File

@ -1,4 +1,3 @@
import { NotFoundError } from "blitz";
import { Queue } from "quirrel/blitz"; import { Queue } from "quirrel/blitz";
import type { PaddleSdkSubscriptionCancelledEvent } from "@devoxa/paddle-sdk"; import type { PaddleSdkSubscriptionCancelledEvent } from "@devoxa/paddle-sdk";
@ -17,7 +16,8 @@ export const subscriptionCancelledQueue = Queue<Payload>("api/queue/subscription
const paddleSubscriptionId = event.subscriptionId; const paddleSubscriptionId = event.subscriptionId;
const subscription = await db.subscription.findFirst({ where: { paddleSubscriptionId } }); const subscription = await db.subscription.findFirst({ where: { paddleSubscriptionId } });
if (!subscription) { if (!subscription) {
throw new NotFoundError(); // user deleted their account, no need to update their subscription
return;
} }
const lastEventTime = event.eventTime; const lastEventTime = event.eventTime;

View File

@ -9,7 +9,6 @@ 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 fetchMessagesQueue from "../../../messages/api/queue/fetch-messages";
import fetchCallsQueue from "../../../phone-calls/api/queue/fetch-calls"; import fetchCallsQueue from "../../../phone-calls/api/queue/fetch-calls";
import setTwilioWebhooks from "./set-twilio-webhooks";
const logger = appLogger.child({ queue: "subscription-created" }); const logger = appLogger.child({ queue: "subscription-created" });
@ -52,7 +51,9 @@ export const subscriptionCreatedQueue = Queue<Payload>("api/queue/subscription-c
}, },
}); });
const phoneNumberId = organization.phoneNumbers[0]!.id; const phoneNumber = organization.phoneNumbers[0];
if (phoneNumber) {
const phoneNumberId = phoneNumber.id;
await Promise.all([ await Promise.all([
db.processingPhoneNumber.create({ db.processingPhoneNumber.create({
data: { data: {
@ -71,6 +72,7 @@ export const subscriptionCreatedQueue = Queue<Payload>("api/queue/subscription-c
{ id: `fetch-messages-${organizationId}-${phoneNumberId}` }, { id: `fetch-messages-${organizationId}-${phoneNumberId}` },
), ),
]); ]);
}
if (isReturningSubscriber) { if (isReturningSubscriber) {
sendEmail({ sendEmail({