Skip to content

Commit

Permalink
feat: add Reply type in putPostsHandler and deletePostsHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
wd-David committed May 15, 2022
1 parent 6dfb7d7 commit f30ea17
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/routes/v1/posts/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const getAllPostsHandler: RouteHandler<{
Querystring: PostsQuery
Reply: GetPostsResponse
}> = async function (req, reply) {
if (req?.query?.deleted !== undefined) {
if (req.query?.deleted !== undefined) {
const { deleted } = req.query
const filteredPosts = posts.filter((post) => post.deleted === deleted)
reply.send({ posts: filteredPosts })
Expand Down Expand Up @@ -44,6 +44,7 @@ export const postPostsHandler: RouteHandler<{
export const putPostsHandler: RouteHandler<{
Params: PostsParams
Body: PostsBody
Reply: Record<string, never> | NotFoundResponse
}> = async function (req, reply) {
const { postid } = req.params
const post = posts.find((p) => p.id == postid)
Expand All @@ -53,19 +54,20 @@ export const putPostsHandler: RouteHandler<{
post.tags = req.body.tags
reply.code(204).send({})
} else {
reply.code(404).send({})
reply.code(404).send({ error: 'Post not found' })
}
}

export const deletePostsHandler: RouteHandler<{
Params: PostsParams
Reply: Record<string, never> | NotFoundResponse
}> = async function (req, reply) {
const { postid } = req.params
const post = posts.find((p) => p.id == postid)
if (post) {
post.deleted = true
reply.code(204).send({})
} else {
reply.code(404).send({})
reply.code(404).send({ error: 'Post not found' })
}
}

0 comments on commit f30ea17

Please sign in to comment.