mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
fix prisma todo location
fix todo
This commit is contained in:
5
.changeset/ripe-colts-say.md
Normal file
5
.changeset/ripe-colts-say.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-better-t-stack": patch
|
||||
---
|
||||
|
||||
fix prisma todo location
|
||||
@@ -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}}
|
||||
Reference in New Issue
Block a user