rallly/packages/backend/trpc/routers/user.ts
2023-07-05 14:46:30 +01:00

38 lines
823 B
TypeScript

import { prisma } from "@rallly/database";
import { z } from "zod";
import { publicProcedure, router } from "../trpc";
export const user = router({
getBilling: publicProcedure.query(async ({ ctx }) => {
return await prisma.userPaymentData.findUnique({
select: {
subscriptionId: true,
status: true,
planId: true,
endDate: true,
updateUrl: true,
cancelUrl: true,
},
where: {
userId: ctx.user.id,
},
});
}),
changeName: publicProcedure
.input(
z.object({
name: z.string().min(1).max(100),
}),
)
.mutation(async ({ input, ctx }) => {
await prisma.user.update({
where: {
id: ctx.user.id,
},
data: {
name: input.name,
},
});
}),
});