Return DB results directly in todo router handlers

This commit is contained in:
Aman Varshney
2025-07-15 15:55:55 +05:30
parent b47671c24d
commit b9e929235d
3 changed files with 10 additions and 10 deletions

View File

@@ -0,0 +1,5 @@
---
"create-better-t-stack": patch
---
Return DB results directly in todo router handlers

View File

@@ -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}}

View File

@@ -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}}