Skip to content

Commit f30ea17

Browse files
committed
feat: add Reply type in putPostsHandler and deletePostsHandler
1 parent 6dfb7d7 commit f30ea17

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/routes/v1/posts/handler.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const getAllPostsHandler: RouteHandler<{
1212
Querystring: PostsQuery
1313
Reply: GetPostsResponse
1414
}> = async function (req, reply) {
15-
if (req?.query?.deleted !== undefined) {
15+
if (req.query?.deleted !== undefined) {
1616
const { deleted } = req.query
1717
const filteredPosts = posts.filter((post) => post.deleted === deleted)
1818
reply.send({ posts: filteredPosts })
@@ -44,6 +44,7 @@ export const postPostsHandler: RouteHandler<{
4444
export const putPostsHandler: RouteHandler<{
4545
Params: PostsParams
4646
Body: PostsBody
47+
Reply: Record<string, never> | NotFoundResponse
4748
}> = async function (req, reply) {
4849
const { postid } = req.params
4950
const post = posts.find((p) => p.id == postid)
@@ -53,19 +54,20 @@ export const putPostsHandler: RouteHandler<{
5354
post.tags = req.body.tags
5455
reply.code(204).send({})
5556
} else {
56-
reply.code(404).send({})
57+
reply.code(404).send({ error: 'Post not found' })
5758
}
5859
}
5960

6061
export const deletePostsHandler: RouteHandler<{
6162
Params: PostsParams
63+
Reply: Record<string, never> | NotFoundResponse
6264
}> = async function (req, reply) {
6365
const { postid } = req.params
6466
const post = posts.find((p) => p.id == postid)
6567
if (post) {
6668
post.deleted = true
6769
reply.code(204).send({})
6870
} else {
69-
reply.code(404).send({})
71+
reply.code(404).send({ error: 'Post not found' })
7072
}
7173
}

0 commit comments

Comments
 (0)