mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-18 03:16:21 +02:00
♻️ Abstract code for getting subscription status
This commit is contained in:
parent
06eca8f61c
commit
fe1933716d
3 changed files with 49 additions and 52 deletions
|
@ -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({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue