File tree Expand file tree Collapse file tree 3 files changed +10
-10
lines changed
apps/cli/templates/examples/todo/server Expand file tree Collapse file tree 3 files changed +10
-10
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " create-better-t-stack " : patch
3
+ ---
4
+
5
+ Return DB results directly in todo router handlers
Original file line number Diff line number Diff line change @@ -13,29 +13,26 @@ export const todoRouter = {
13
13
create: publicProcedure
14
14
.input(z.object({ text: z.string().min(1) }))
15
15
.handler(async ({ input }) => {
16
- const result = await db
16
+ return await db
17
17
.insert(todo)
18
18
.values({
19
19
text: input.text,
20
20
});
21
- return result[0];
22
21
}),
23
22
24
23
toggle: publicProcedure
25
24
.input(z.object({ id: z.number(), completed: z.boolean() }))
26
25
.handler(async ({ input }) => {
27
- await db
26
+ return await db
28
27
.update(todo)
29
28
.set({ completed: input.completed })
30
29
.where(eq(todo.id, input.id));
31
- return { success: true };
32
30
}),
33
31
34
32
delete: publicProcedure
35
33
.input(z.object({ id: z.number() }))
36
34
.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));
39
36
}),
40
37
};
41
38
{{ /if }}
Original file line number Diff line number Diff line change @@ -29,11 +29,10 @@ export const todoRouter = {
29
29
.input(z.object({ id: z.number(), completed: z.boolean() }))
30
30
{{ /if }}
31
31
.handler(async ({ input }) => {
32
- await prisma.todo.update({
32
+ return await prisma.todo.update({
33
33
where: { id: input.id },
34
34
data: { completed: input.completed },
35
35
});
36
- return { success: true };
37
36
}),
38
37
39
38
delete: publicProcedure
@@ -43,10 +42,9 @@ export const todoRouter = {
43
42
.input(z.object({ id: z.number() }))
44
43
{{ /if }}
45
44
.handler(async ({ input }) => {
46
- await prisma.todo.delete({
45
+ return await prisma.todo.delete({
47
46
where: { id: input.id },
48
47
});
49
- return { success: true };
50
48
}),
51
49
};
52
50
{{ /if }}
You can’t perform that action at this time.
0 commit comments