rallly/packages/backend/trpc/routers/polls/options.ts
Luke Vella c22b3abc4d
⬆️ v3.0.0 (#704)
2023-06-19 17:17:00 +01:00

45 lines
879 B
TypeScript

import { prisma } from "@rallly/database";
import { z } from "zod";
import { publicProcedure, router } from "../../trpc";
export const options = router({
list: publicProcedure
.input(
z.object({
pollId: z.string(),
}),
)
.query(async ({ input: { pollId } }) => {
const options = await prisma.option.findMany({
where: {
pollId,
},
select: {
id: true,
start: true,
duration: true,
},
orderBy: [
{
start: "asc",
},
],
});
return options;
}),
delete: publicProcedure
.input(
z.object({
optionId: z.string(),
}),
)
.mutation(async ({ input: { optionId } }) => {
await prisma.option.delete({
where: {
id: optionId,
},
});
}),
});