deleteTodo.ts12 lines · main
| 1 | import { brivenError, mutation, type Ctx } from '@briven/cli/server'; |
| 2 | |
| 3 | interface Args { |
| 4 | id: string; |
| 5 | } |
| 6 | |
| 7 | export default mutation(async (ctx: Ctx, args: Args) => { |
| 8 | if (!args.id) throw new brivenError('validation_failed', 'id is required', { status: 400 }); |
| 9 | const affected = await ctx.db('todos').delete().where({ id: args.id }); |
| 10 | if (affected === 0) throw new brivenError('not_found', `no todo ${args.id}`, { status: 404 }); |
| 11 | return { id: args.id, deleted: true }; |
| 12 | }); |