shellphone.app/app/settings/queries/get-subscription.ts

22 lines
532 B
TypeScript
Raw Normal View History

2021-09-30 22:59:35 +00:00
import { resolver } from "blitz";
2021-09-26 22:44:26 +00:00
import db, { Prisma, SubscriptionStatus } from "db";
2021-09-26 22:44:26 +00:00
2021-09-30 22:59:35 +00:00
export default resolver.pipe(resolver.authorize(), async (_ = null, { session }) => {
2021-09-26 22:44:26 +00:00
if (!session.orgId) return null;
2021-10-01 22:19:06 +00:00
return db.subscription.findFirst({
where: {
organizationId: session.orgId,
OR: [
{ status: { not: SubscriptionStatus.deleted } },
{
status: SubscriptionStatus.deleted,
cancellationEffectiveDate: { gt: new Date() },
},
],
2021-10-01 22:19:06 +00:00
},
orderBy: { lastEventTime: Prisma.SortOrder.desc },
2021-10-01 22:19:06 +00:00
});
2021-09-30 22:59:35 +00:00
});