boring.tools-poc/apps/api/src/changelog/delete.ts
Lars Hampe 0d0e241e68
All checks were successful
Build and Push Docker Image / build (push) Successful in 1m35s
feat(api): add changelog routes and tests
2024-10-01 13:37:26 +02:00

45 lines
973 B
TypeScript

import { changelog, db } from '@boring.tools/database'
import { GeneralOutput } from '@boring.tools/schema'
import { createRoute } from '@hono/zod-openapi'
import { and, eq } from 'drizzle-orm'
import { HTTPException } from 'hono/http-exception'
export const route = createRoute({
method: 'delete',
path: '/:id',
responses: {
200: {
content: {
'application/json': {
schema: GeneralOutput,
},
},
description: 'Removes a changelog by id',
},
400: {
description: 'Bad Request',
},
500: {
description: 'Internal Server Error',
},
},
})
export const func = async ({ userId, id }: { userId: string; id: string }) => {
const result = await db
.delete(changelog)
.where(and(eq(changelog.userId, userId), eq(changelog.id, id)))
.returning()
if (!result) {
throw new HTTPException(404, { message: 'Not found' })
}
return result
}
export default {
route,
func,
}