Skip to content

Commit b9e9292

Browse files
Return DB results directly in todo router handlers
1 parent b47671c commit b9e9292

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

.changeset/moody-news-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-better-t-stack": patch
3+
---
4+
5+
Return DB results directly in todo router handlers

apps/cli/templates/examples/todo/server/drizzle/base/src/routers/todo.ts.hbs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,26 @@ export const todoRouter = {
1313
create: publicProcedure
1414
.input(z.object({ text: z.string().min(1) }))
1515
.handler(async ({ input }) => {
16-
const result = await db
16+
return await db
1717
.insert(todo)
1818
.values({
1919
text: input.text,
2020
});
21-
return result[0];
2221
}),
2322

2423
toggle: publicProcedure
2524
.input(z.object({ id: z.number(), completed: z.boolean() }))
2625
.handler(async ({ input }) => {
27-
await db
26+
return await db
2827
.update(todo)
2928
.set({ completed: input.completed })
3029
.where(eq(todo.id, input.id));
31-
return { success: true };
3230
}),
3331

3432
delete: publicProcedure
3533
.input(z.object({ id: z.number() }))
3634
.handler(async ({ input }) => {
37-
await db.delete(todo).where(eq(todo.id, input.id));
38-
return { success: true };
35+
return await db.delete(todo).where(eq(todo.id, input.id));
3936
}),
4037
};
4138
{{/if}}

apps/cli/templates/examples/todo/server/prisma/base/src/routers/todo.ts.hbs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ export const todoRouter = {
2929
.input(z.object({ id: z.number(), completed: z.boolean() }))
3030
{{/if}}
3131
.handler(async ({ input }) => {
32-
await prisma.todo.update({
32+
return await prisma.todo.update({
3333
where: { id: input.id },
3434
data: { completed: input.completed },
3535
});
36-
return { success: true };
3736
}),
3837

3938
delete: publicProcedure
@@ -43,10 +42,9 @@ export const todoRouter = {
4342
.input(z.object({ id: z.number() }))
4443
{{/if}}
4544
.handler(async ({ input }) => {
46-
await prisma.todo.delete({
45+
return await prisma.todo.delete({
4746
where: { id: input.id },
4847
});
49-
return { success: true };
5048
}),
5149
};
5250
{{/if}}

0 commit comments

Comments
 (0)