mirror of
https://github.com/hknsh/project-knedita.git
synced 2024-11-29 01:41:16 +00:00
26 lines
663 B
TypeScript
26 lines
663 B
TypeScript
import comment from 'services/comments'
|
|
import type { Request, Response } from 'express'
|
|
import { badRequest } from 'helpers/http-errors'
|
|
import handleResponse from 'helpers/handle-response'
|
|
|
|
async function commentCreateController (
|
|
req: Request,
|
|
res: Response
|
|
): Promise<void> {
|
|
const { content, postId } = req.body
|
|
const id = req.user?.id ?? ''
|
|
|
|
if (postId === undefined) {
|
|
badRequest(res, 'Expected post id'); return
|
|
}
|
|
|
|
if (content === undefined) {
|
|
badRequest(res, 'Expected comment content'); return
|
|
}
|
|
|
|
const result = await comment.create(postId, content, id)
|
|
|
|
handleResponse(res, result)
|
|
}
|
|
|
|
export default commentCreateController
|