From c770cccd259429ca55d95412cec5135979b427d8 Mon Sep 17 00:00:00 2001 From: Muhammad Swalah A A Date: Sun, 12 Nov 2023 08:12:16 +0530 Subject: [PATCH] feat: implement request body validation for /news/annotate api --- src/api/routes/newsRoute.ts | 8 +++++++- src/validations/newsRouteSchemas.ts | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/api/routes/newsRoute.ts b/src/api/routes/newsRoute.ts index 3fdf28e..78479e8 100644 --- a/src/api/routes/newsRoute.ts +++ b/src/api/routes/newsRoute.ts @@ -17,7 +17,10 @@ import { iNewsSubmissionDTO, } from "customTypes/appDataTypes/newsTypes"; import {celebrate, Segments} from "celebrate"; -import {newsSubmissionBodySchema} from "validations/newsRouteSchemas"; +import { + newsAnnotationBodySchema, + newsSubmissionBodySchema, +} from "validations/newsRouteSchemas"; import NewsService from "services/NewsService"; const route = Router(); @@ -80,6 +83,9 @@ const newsRoute: RouteType = (apiRouter) => { route.post( "/annotate", + celebrate({ + [Segments.BODY]: newsAnnotationBodySchema, + }), async ( req: iRequest, res: iResponse, diff --git a/src/validations/newsRouteSchemas.ts b/src/validations/newsRouteSchemas.ts index 6b106ae..8c9049c 100644 --- a/src/validations/newsRouteSchemas.ts +++ b/src/validations/newsRouteSchemas.ts @@ -11,4 +11,9 @@ const newsSubmissionBodySchema = Joi.object({ date: Joi.string().isoDate().required(), }); -export {newsIdSchema, newsSubmissionBodySchema}; +const newsAnnotationBodySchema = Joi.object({ + newsId: Joi.string().uuid().required(), + annotations: Joi.array().items(Joi.string().uuid()).required().min(1), +}); + +export {newsIdSchema, newsSubmissionBodySchema, newsAnnotationBodySchema};