mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
Return DB results directly in todo router handlers
This commit is contained in:
5
.changeset/moody-news-change.md
Normal file
5
.changeset/moody-news-change.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-better-t-stack": patch
|
||||
---
|
||||
|
||||
Return DB results directly in todo router handlers
|
||||
@@ -13,29 +13,26 @@ export const todoRouter = {
|
||||
create: publicProcedure
|
||||
.input(z.object({ text: z.string().min(1) }))
|
||||
.handler(async ({ input }) => {
|
||||
const result = await db
|
||||
return await db
|
||||
.insert(todo)
|
||||
.values({
|
||||
text: input.text,
|
||||
});
|
||||
return result[0];
|
||||
}),
|
||||
|
||||
toggle: publicProcedure
|
||||
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
||||
.handler(async ({ input }) => {
|
||||
await db
|
||||
return await db
|
||||
.update(todo)
|
||||
.set({ completed: input.completed })
|
||||
.where(eq(todo.id, input.id));
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
delete: publicProcedure
|
||||
.input(z.object({ id: z.number() }))
|
||||
.handler(async ({ input }) => {
|
||||
await db.delete(todo).where(eq(todo.id, input.id));
|
||||
return { success: true };
|
||||
return await db.delete(todo).where(eq(todo.id, input.id));
|
||||
}),
|
||||
};
|
||||
{{/if}}
|
||||
|
||||
@@ -29,11 +29,10 @@ export const todoRouter = {
|
||||
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
||||
{{/if}}
|
||||
.handler(async ({ input }) => {
|
||||
await prisma.todo.update({
|
||||
return await prisma.todo.update({
|
||||
where: { id: input.id },
|
||||
data: { completed: input.completed },
|
||||
});
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
delete: publicProcedure
|
||||
@@ -43,10 +42,9 @@ export const todoRouter = {
|
||||
.input(z.object({ id: z.number() }))
|
||||
{{/if}}
|
||||
.handler(async ({ input }) => {
|
||||
await prisma.todo.delete({
|
||||
return await prisma.todo.delete({
|
||||
where: { id: input.id },
|
||||
});
|
||||
return { success: true };
|
||||
}),
|
||||
};
|
||||
{{/if}}
|
||||
|
||||
Reference in New Issue
Block a user