Skip to content

Commit c770ccc

Browse files
committed
feat: implement request body validation for /news/annotate api
1 parent 0b3ff93 commit c770ccc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/api/routes/newsRoute.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import {
1717
iNewsSubmissionDTO,
1818
} from "customTypes/appDataTypes/newsTypes";
1919
import {celebrate, Segments} from "celebrate";
20-
import {newsSubmissionBodySchema} from "validations/newsRouteSchemas";
20+
import {
21+
newsAnnotationBodySchema,
22+
newsSubmissionBodySchema,
23+
} from "validations/newsRouteSchemas";
2124
import NewsService from "services/NewsService";
2225

2326
const route = Router();
@@ -80,6 +83,9 @@ const newsRoute: RouteType = (apiRouter) => {
8083

8184
route.post(
8285
"/annotate",
86+
celebrate({
87+
[Segments.BODY]: newsAnnotationBodySchema,
88+
}),
8389
async (
8490
req: iRequest<iNewsAnnotationsInputDTO>,
8591
res: iResponse<null>,

src/validations/newsRouteSchemas.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ const newsSubmissionBodySchema = Joi.object({
1111
date: Joi.string().isoDate().required(),
1212
});
1313

14-
export {newsIdSchema, newsSubmissionBodySchema};
14+
const newsAnnotationBodySchema = Joi.object({
15+
newsId: Joi.string().uuid().required(),
16+
annotations: Joi.array().items(Joi.string().uuid()).required().min(1),
17+
});
18+
19+
export {newsIdSchema, newsSubmissionBodySchema, newsAnnotationBodySchema};

0 commit comments

Comments
 (0)