Skip to content

Commit

Permalink
feat: implement request body validation for /news/annotate api
Browse files Browse the repository at this point in the history
  • Loading branch information
swalahamani committed Nov 12, 2023
1 parent 0b3ff93 commit c770ccc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/api/routes/newsRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -80,6 +83,9 @@ const newsRoute: RouteType = (apiRouter) => {

route.post(
"/annotate",
celebrate({
[Segments.BODY]: newsAnnotationBodySchema,
}),
async (
req: iRequest<iNewsAnnotationsInputDTO>,
res: iResponse<null>,
Expand Down
7 changes: 6 additions & 1 deletion src/validations/newsRouteSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};

0 comments on commit c770ccc

Please sign in to comment.