fix prisma todo location

fix todo
This commit is contained in:
Aman Varshney
2025-04-24 08:13:00 +05:30
parent 3d0fcba360
commit 9c125c2757
2 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"create-better-t-stack": patch
---
fix prisma todo location

View File

@@ -1,3 +1,49 @@
{{#if (eq api "orpc")}}
import { z } from "zod";
import prisma from "../../prisma";
import { publicProcedure } from "../lib/orpc";
export const todoRouter = {
getAll: publicProcedure.handler(async () => {
return await prisma.todo.findMany({
orderBy: {
id: "asc",
},
});
}),
create: publicProcedure
.input(z.object({ text: z.string().min(1) }))
.handler(async ({ input }) => {
return await prisma.todo.create({
data: {
text: input.text,
},
});
}),
toggle: publicProcedure
.input(z.object({ id: z.number(), completed: z.boolean() }))
.handler(async ({ input }) => {
await prisma.todo.update({
where: { id: input.id },
data: { completed: input.completed },
});
return { success: true };
}),
delete: publicProcedure
.input(z.object({ id: z.number() }))
.handler(async ({ input }) => {
await prisma.todo.delete({
where: { id: input.id },
});
return { success: true };
}),
};
{{/if}}
{{#if (eq api "trpc")}}
import { TRPCError } from "@trpc/server";
import { z } from "zod";
import prisma from "../../prisma";
@@ -53,3 +99,4 @@ export const todoRouter = router({
}
}),
});
{{/if}}