@@ -12,7 +12,7 @@ export const getAllPostsHandler: RouteHandler<{
12
12
Querystring : PostsQuery
13
13
Reply : GetPostsResponse
14
14
} > = async function ( req , reply ) {
15
- if ( req ? .query ?. deleted !== undefined ) {
15
+ if ( req . query ?. deleted !== undefined ) {
16
16
const { deleted } = req . query
17
17
const filteredPosts = posts . filter ( ( post ) => post . deleted === deleted )
18
18
reply . send ( { posts : filteredPosts } )
@@ -44,6 +44,7 @@ export const postPostsHandler: RouteHandler<{
44
44
export const putPostsHandler : RouteHandler < {
45
45
Params : PostsParams
46
46
Body : PostsBody
47
+ Reply : Record < string , never > | NotFoundResponse
47
48
} > = async function ( req , reply ) {
48
49
const { postid } = req . params
49
50
const post = posts . find ( ( p ) => p . id == postid )
@@ -53,19 +54,20 @@ export const putPostsHandler: RouteHandler<{
53
54
post . tags = req . body . tags
54
55
reply . code ( 204 ) . send ( { } )
55
56
} else {
56
- reply . code ( 404 ) . send ( { } )
57
+ reply . code ( 404 ) . send ( { error : 'Post not found' } )
57
58
}
58
59
}
59
60
60
61
export const deletePostsHandler : RouteHandler < {
61
62
Params : PostsParams
63
+ Reply : Record < string , never > | NotFoundResponse
62
64
} > = async function ( req , reply ) {
63
65
const { postid } = req . params
64
66
const post = posts . find ( ( p ) => p . id == postid )
65
67
if ( post ) {
66
68
post . deleted = true
67
69
reply . code ( 204 ) . send ( { } )
68
70
} else {
69
- reply . code ( 404 ) . send ( { } )
71
+ reply . code ( 404 ) . send ( { error : 'Post not found' } )
70
72
}
71
73
}
0 commit comments