always pick the most recent subscription
This commit is contained in:
parent
c0554f321c
commit
a4ac0384c2
@ -2,7 +2,7 @@ import type { BlitzApiRequest, BlitzApiResponse } from "blitz";
|
||||
import twilio from "twilio";
|
||||
|
||||
import appLogger from "../../../../integrations/logger";
|
||||
import db, { SubscriptionStatus } from "../../../../db";
|
||||
import db, { Prisma, SubscriptionStatus } from "../../../../db";
|
||||
import insertIncomingMessageQueue from "../queue/insert-incoming-message";
|
||||
import { smsUrl } from "../../../../integrations/twilio";
|
||||
import type { ApiError } from "../../../core/types";
|
||||
@ -44,7 +44,16 @@ export default async function incomingMessageHandler(req: BlitzApiRequest, res:
|
||||
organization: {
|
||||
include: {
|
||||
subscriptions: {
|
||||
where: { status: SubscriptionStatus.active },
|
||||
where: {
|
||||
OR: [
|
||||
{ status: { not: SubscriptionStatus.deleted } },
|
||||
{
|
||||
status: SubscriptionStatus.deleted,
|
||||
cancellationEffectiveDate: { gt: new Date() },
|
||||
},
|
||||
],
|
||||
},
|
||||
orderBy: { lastEventTime: Prisma.SortOrder.desc },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -2,7 +2,7 @@ import type { BlitzApiRequest, BlitzApiResponse } from "blitz";
|
||||
import twilio from "twilio";
|
||||
|
||||
import type { ApiError } from "app/core/types";
|
||||
import db, { Direction, SubscriptionStatus } from "db";
|
||||
import db, { Direction, Prisma, SubscriptionStatus } from "db";
|
||||
import appLogger from "integrations/logger";
|
||||
import { translateCallStatus, voiceUrl } from "integrations/twilio";
|
||||
import updateCallDurationQueue from "../queue/update-call-duration";
|
||||
@ -36,7 +36,16 @@ export default async function incomingCallHandler(req: BlitzApiRequest, res: Bli
|
||||
organization: {
|
||||
include: {
|
||||
subscriptions: {
|
||||
where: { status: SubscriptionStatus.active },
|
||||
where: {
|
||||
OR: [
|
||||
{ status: { not: SubscriptionStatus.deleted } },
|
||||
{
|
||||
status: SubscriptionStatus.deleted,
|
||||
cancellationEffectiveDate: { gt: new Date() },
|
||||
},
|
||||
],
|
||||
},
|
||||
orderBy: { lastEventTime: Prisma.SortOrder.desc },
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -101,7 +110,16 @@ export default async function incomingCallHandler(req: BlitzApiRequest, res: Bli
|
||||
organization: {
|
||||
include: {
|
||||
subscriptions: {
|
||||
where: { status: SubscriptionStatus.active },
|
||||
where: {
|
||||
OR: [
|
||||
{ status: { not: SubscriptionStatus.deleted } },
|
||||
{
|
||||
status: SubscriptionStatus.deleted,
|
||||
cancellationEffectiveDate: { gt: new Date() },
|
||||
},
|
||||
],
|
||||
},
|
||||
orderBy: { lastEventTime: Prisma.SortOrder.desc },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { NotFoundError, resolver } from "blitz";
|
||||
import { z } from "zod";
|
||||
|
||||
import db from "db";
|
||||
import db, { Prisma, SubscriptionStatus } from "db";
|
||||
import { updateSubscriptionPlan } from "integrations/paddle";
|
||||
|
||||
const Body = z.object({
|
||||
@ -9,7 +9,13 @@ const Body = z.object({
|
||||
});
|
||||
|
||||
export default resolver.pipe(resolver.zod(Body), resolver.authorize(), async ({ planId }, ctx) => {
|
||||
const subscription = await db.subscription.findFirst({ where: { organizationId: ctx.session.orgId } });
|
||||
const subscription = await db.subscription.findFirst({
|
||||
where: {
|
||||
organizationId: ctx.session.orgId,
|
||||
status: { not: SubscriptionStatus.deleted },
|
||||
},
|
||||
orderBy: { lastEventTime: Prisma.SortOrder.desc },
|
||||
});
|
||||
if (!subscription) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { resolver } from "blitz";
|
||||
|
||||
import db, { SubscriptionStatus } from "db";
|
||||
import db, { Prisma, SubscriptionStatus } from "db";
|
||||
|
||||
export default resolver.pipe(resolver.authorize(), async (_ = null, { session }) => {
|
||||
if (!session.orgId) return null;
|
||||
@ -8,7 +8,14 @@ export default resolver.pipe(resolver.authorize(), async (_ = null, { session })
|
||||
return db.subscription.findFirst({
|
||||
where: {
|
||||
organizationId: session.orgId,
|
||||
OR: [{ status: { not: SubscriptionStatus.deleted } }, { cancellationEffectiveDate: { gt: new Date() } }],
|
||||
OR: [
|
||||
{ status: { not: SubscriptionStatus.deleted } },
|
||||
{
|
||||
status: SubscriptionStatus.deleted,
|
||||
cancellationEffectiveDate: { gt: new Date() },
|
||||
},
|
||||
],
|
||||
},
|
||||
orderBy: { lastEventTime: Prisma.SortOrder.desc },
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type { Ctx } from "blitz";
|
||||
|
||||
import db, { SubscriptionStatus } from "db";
|
||||
import db, { Prisma, SubscriptionStatus } from "db";
|
||||
|
||||
export default async function getCurrentUser(_ = null, { session }: Ctx) {
|
||||
if (!session.userId) return null;
|
||||
@ -26,6 +26,7 @@ export default async function getCurrentUser(_ = null, { session }: Ctx) {
|
||||
},
|
||||
],
|
||||
},
|
||||
orderBy: { lastEventTime: Prisma.SortOrder.desc },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user