Hozifa Elgherbawy commited on
Commit
4bad94c
·
unverified ·
2 Parent(s): ca710a2 b72a7d4

Merge pull request #76 from Modarb-Ai-Trainer:requestSchema

Browse files

feat: Add validation for target muscles and cover image in create exercise API

src/lib/decorators/swagger-request.decorator.ts CHANGED
@@ -6,14 +6,21 @@ const parseToSchema = (schema: any, joiSchema: any) => {
6
  const properties = Object.getOwnPropertyNames(joiSchema);
7
  properties.forEach((property) => {
8
  const type = joiSchema[property].type;
9
- if (type === "object") {
 
 
 
 
 
 
 
10
  schema.properties[property] = {
11
  type: "object",
12
  properties: {},
13
  };
14
  parseToSchema(schema.properties[property], joiSchema[property]);
15
  } else {
16
- schema.properties[property] = {type};
17
  }
18
  });
19
  }
 
6
  const properties = Object.getOwnPropertyNames(joiSchema);
7
  properties.forEach((property) => {
8
  const type = joiSchema[property].type;
9
+ if (type === "array") {
10
+ schema.properties[property] = {
11
+ type: "array",
12
+ items: {
13
+ type: joiSchema[property].items.type,
14
+ },
15
+ };
16
+ } else if (type === "object") {
17
  schema.properties[property] = {
18
  type: "object",
19
  properties: {},
20
  };
21
  parseToSchema(schema.properties[property], joiSchema[property]);
22
  } else {
23
+ schema.properties[property] = { type };
24
  }
25
  });
26
  }
src/modules/console/modules/exercises/validations/create-excercise.validation.ts CHANGED
@@ -67,14 +67,27 @@ export const createExerciseSchema = createSchema<ICreateExercise>({
67
  "any.required": "benefits is required",
68
  "string.empty": "benefits can not be empty",
69
  }),
70
- targetMuscles: joi.object().empty().required().messages({
71
- "array.base": "please enter a valid target muscles",
72
- "any.required": "target muscles is required",
 
 
 
 
 
 
 
 
73
  }),
74
  equipments: joi.array().items(joi.string()).empty().required().messages({
75
  "array.base": "please enter a valid equipments",
76
  "any.required": "equipments is required",
77
  }),
 
 
 
 
 
78
  media: joi.object().keys({
79
  type: joi.string().valid("image", "video").required().messages({
80
  "string.base": "please enter a valid media type",
 
67
  "any.required": "benefits is required",
68
  "string.empty": "benefits can not be empty",
69
  }),
70
+ targetMuscles: joi.object().keys({
71
+ primary: joi.string().empty().required().messages({
72
+ "string.base": "please enter a valid primary target muscle",
73
+ "any.required": "primary target muscle is required",
74
+ "string.empty": "primary target muscle can not be empty",
75
+ }),
76
+ secondary: joi.string().empty().required().messages({
77
+ "string.base": "please enter a valid secondary target muscle",
78
+ "any.required": "secondary target muscle is required",
79
+ "string.empty": "secondary target muscle can not be empty",
80
+ }),
81
  }),
82
  equipments: joi.array().items(joi.string()).empty().required().messages({
83
  "array.base": "please enter a valid equipments",
84
  "any.required": "equipments is required",
85
  }),
86
+ coverImage: joi.string().empty().required().messages({
87
+ "string.base": "please enter a valid cover image",
88
+ "any.required": "cover image is required",
89
+ "string.empty": "cover image can not be empty",
90
+ }),
91
  media: joi.object().keys({
92
  type: joi.string().valid("image", "video").required().messages({
93
  "string.base": "please enter a valid media type",
src/modules/console/modules/meals/validations/create-meals.validation.ts CHANGED
@@ -5,7 +5,7 @@ import { MealType } from "@common/enums/meal-type.enum";
5
  export interface ICreateMeal {
6
  name: string;
7
  created_at?: Date;
8
- ingredients: [string];
9
  calories: number;
10
  carbs: number;
11
  proteins: number;
@@ -23,15 +23,16 @@ export const createMealSchema = createSchema<ICreateMeal>({
23
  "date.base": "please enter a valid created_at",
24
  "date.empty": "created_at can not be empty",
25
  }),
26
- ingredients: joi.array().items(joi.string()).required().messages({
27
- "array.base": "please enter a valid ingredients",
28
- "any.required": "ingredients is required",
29
- }),
30
  calories: joi.number().empty().required().messages({
31
  "number.base": "please enter a valid calories",
32
  "any.required": "calories is required",
33
  "number.empty": "calories can not be empty",
34
  }),
 
 
 
 
35
  carbs: joi.number().empty().required().messages({
36
  "number.base": "please enter a valid carbs",
37
  "any.required": "carbs is required",
 
5
  export interface ICreateMeal {
6
  name: string;
7
  created_at?: Date;
8
+ ingredients: string[];
9
  calories: number;
10
  carbs: number;
11
  proteins: number;
 
23
  "date.base": "please enter a valid created_at",
24
  "date.empty": "created_at can not be empty",
25
  }),
26
+
 
 
 
27
  calories: joi.number().empty().required().messages({
28
  "number.base": "please enter a valid calories",
29
  "any.required": "calories is required",
30
  "number.empty": "calories can not be empty",
31
  }),
32
+ ingredients: joi.array().items(joi.string()).required().messages({
33
+ "array.base": "please enter a valid ingredients",
34
+ "any.required": "ingredients is required",
35
+ }),
36
  carbs: joi.number().empty().required().messages({
37
  "number.base": "please enter a valid carbs",
38
  "any.required": "carbs is required",