mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-23 05:46:20 +02:00
💳 Support payments with Stripe (#822)
This commit is contained in:
parent
969ae35971
commit
6f425edeaa
20 changed files with 712 additions and 229 deletions
|
@ -1,10 +1,10 @@
|
|||
import { prisma } from "@rallly/database";
|
||||
import { z } from "zod";
|
||||
|
||||
import { publicProcedure, router } from "../trpc";
|
||||
import { privateProcedure, router } from "../trpc";
|
||||
|
||||
export const user = router({
|
||||
getBilling: publicProcedure.query(async ({ ctx }) => {
|
||||
getBilling: privateProcedure.query(async ({ ctx }) => {
|
||||
return await prisma.userPaymentData.findUnique({
|
||||
select: {
|
||||
subscriptionId: true,
|
||||
|
@ -19,7 +19,50 @@ export const user = router({
|
|||
},
|
||||
});
|
||||
}),
|
||||
changeName: publicProcedure
|
||||
subscription: privateProcedure.query(async ({ ctx }) => {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: ctx.user.id,
|
||||
},
|
||||
select: {
|
||||
subscription: {
|
||||
select: {
|
||||
active: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (user?.subscription?.active === true) {
|
||||
return {
|
||||
active: true,
|
||||
};
|
||||
}
|
||||
|
||||
const userPaymentData = await prisma.userPaymentData.findUnique({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
},
|
||||
select: {
|
||||
endDate: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (
|
||||
userPaymentData?.endDate &&
|
||||
userPaymentData.endDate.getTime() > Date.now()
|
||||
) {
|
||||
return {
|
||||
active: true,
|
||||
legacy: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
active: false,
|
||||
};
|
||||
}),
|
||||
changeName: privateProcedure
|
||||
.input(
|
||||
z.object({
|
||||
name: z.string().min(1).max(100),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue