This commit is contained in:
Aman Varshney
2025-04-14 21:45:28 +05:30
parent 8b03441909
commit 7f441ef670
268 changed files with 3513 additions and 3039 deletions

View File

@@ -0,0 +1,55 @@
import { TRPCError } from "@trpc/server";
import { z } from "zod";
import prisma from "../../prisma";
import { publicProcedure, router } from "../lib/trpc";
export const todoRouter = router({
getAll: publicProcedure.query(async () => {
return await prisma.todo.findMany({
orderBy: {
id: "asc"
}
});
}),
create: publicProcedure
.input(z.object({ text: z.string().min(1) }))
.mutation(async ({ input }) => {
return await prisma.todo.create({
data: {
text: input.text,
},
});
}),
toggle: publicProcedure
.input(z.object({ id: z.number(), completed: z.boolean() }))
.mutation(async ({ input }) => {
try {
return await prisma.todo.update({
where: { id: input.id },
data: { completed: input.completed },
});
} catch (error) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Todo not found",
});
}
}),
delete: publicProcedure
.input(z.object({ id: z.number() }))
.mutation(async ({ input }) => {
try {
return await prisma.todo.delete({
where: { id: input.id },
});
} catch (error) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Todo not found",
});
}
}),
});

View File

@@ -0,0 +1,7 @@
model Todo {
id String @id @default(auto()) @map("_id") @db.ObjectId
text String
completed Boolean @default(false)
@@map("todo")
}

View File

@@ -0,0 +1,7 @@
model Todo {
id Int @id @default(autoincrement())
text String
completed Boolean @default(false)
@@map("todo")
}

View File

@@ -0,0 +1,7 @@
model Todo {
id Int @id @default(autoincrement())
text String
completed Boolean @default(false)
@@map("todo")
}

View File

@@ -0,0 +1,7 @@
model Todo {
id Int @id @default(autoincrement())
text String
completed Boolean @default(false)
@@map("todo")
}