♻️ Abstract code for getting subscription status

This commit is contained in:
Luke Vella 2023-08-23 19:47:25 +01:00
parent 06eca8f61c
commit fe1933716d
3 changed files with 49 additions and 52 deletions

View file

@ -1,7 +1,7 @@
import { prisma } from "@rallly/database";
import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
import { getSubscriptionStatus } from "../utils/auth";
import { Context } from "./context";
const t = initTRPC.context<Context>().create({
@ -38,16 +38,7 @@ export const proProcedure = t.procedure.use(
});
}
const isPro = Boolean(
await prisma.userPaymentData.findFirst({
where: {
userId: ctx.user.id,
endDate: {
gt: new Date(),
},
},
}),
);
const { active: isPro } = await getSubscriptionStatus(ctx.user.id);
if (!isPro) {
throw new TRPCError({