boring.tools-poc/apps/api/src/changelog/create.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

54 lines
969 B
TypeScript

import { changelog, db } from '@boring.tools/database'
import {
ChangelogCreateInput,
ChangelogCreateOutput,
} from '@boring.tools/schema'
import { createRoute, type z } from '@hono/zod-openapi'
export const route = createRoute({
method: 'post',
path: '/',
request: {
body: {
content: {
'application/json': { schema: ChangelogCreateInput },
},
},
},
responses: {
201: {
content: {
'application/json': { schema: ChangelogCreateOutput },
},
description: 'Return created changelog',
},
400: {
description: 'Bad Request',
},
500: {
description: 'Internal Server Error',
},
},
})
export const func = async ({
userId,
payload,
}: {
userId: string
payload: z.infer<typeof ChangelogCreateInput>
}) => {
return await db
.insert(changelog)
.values({
...payload,
userId: userId,
})
.returning()
}
export default {
route,
func,
}