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
|
create: publicProcedure
|
||||||
.input(z.object({ text: z.string().min(1) }))
|
.input(z.object({ text: z.string().min(1) }))
|
||||||
.handler(async ({ input }) => {
|
.handler(async ({ input }) => {
|
||||||
const result = await db
|
return await db
|
||||||
.insert(todo)
|
.insert(todo)
|
||||||
.values({
|
.values({
|
||||||
text: input.text,
|
text: input.text,
|
||||||
});
|
});
|
||||||
return result[0];
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
toggle: publicProcedure
|
toggle: publicProcedure
|
||||||
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
||||||
.handler(async ({ input }) => {
|
.handler(async ({ input }) => {
|
||||||
await db
|
return await db
|
||||||
.update(todo)
|
.update(todo)
|
||||||
.set({ completed: input.completed })
|
.set({ completed: input.completed })
|
||||||
.where(eq(todo.id, input.id));
|
.where(eq(todo.id, input.id));
|
||||||
return { success: true };
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
delete: publicProcedure
|
delete: publicProcedure
|
||||||
.input(z.object({ id: z.number() }))
|
.input(z.object({ id: z.number() }))
|
||||||
.handler(async ({ input }) => {
|
.handler(async ({ input }) => {
|
||||||
await db.delete(todo).where(eq(todo.id, input.id));
|
return await db.delete(todo).where(eq(todo.id, input.id));
|
||||||
return { success: true };
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|||||||
@@ -29,11 +29,10 @@ export const todoRouter = {
|
|||||||
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
||||||
{{/if}}
|
{{/if}}
|
||||||
.handler(async ({ input }) => {
|
.handler(async ({ input }) => {
|
||||||
await prisma.todo.update({
|
return await prisma.todo.update({
|
||||||
where: { id: input.id },
|
where: { id: input.id },
|
||||||
data: { completed: input.completed },
|
data: { completed: input.completed },
|
||||||
});
|
});
|
||||||
return { success: true };
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
delete: publicProcedure
|
delete: publicProcedure
|
||||||
@@ -43,10 +42,9 @@ export const todoRouter = {
|
|||||||
.input(z.object({ id: z.number() }))
|
.input(z.object({ id: z.number() }))
|
||||||
{{/if}}
|
{{/if}}
|
||||||
.handler(async ({ input }) => {
|
.handler(async ({ input }) => {
|
||||||
await prisma.todo.delete({
|
return await prisma.todo.delete({
|
||||||
where: { id: input.id },
|
where: { id: input.id },
|
||||||
});
|
});
|
||||||
return { success: true };
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|||||||
Reference in New Issue
Block a user