Spaces:
Running
Running
Hozifa Elgharbawy
commited on
Commit
·
b561958
1
Parent(s):
c7ae7c3
refactor: Add image property to meal serialization and populate serialization
Browse files- src/common/models/meal.model.ts +2 -0
- src/common/serializers/meal.serialization.ts +4 -0
- src/common/serializers/mealPopulate.serialization.ts +4 -0
- src/modules/console/modules/meals/validations/create-meals.validation.ts +7 -0
- src/modules/console/modules/meals/validations/update-meals.validation.ts +5 -0
- src/resources/meals1.json +0 -0
- src/resources/meals2.json +0 -0
- src/seeder/seeders/9-meals.seeder.ts +2 -0
src/common/models/meal.model.ts
CHANGED
@@ -4,6 +4,7 @@ import { MealType } from "@common/enums/meal-type.enum";
|
|
4 |
export interface IMeal {
|
5 |
name: string;
|
6 |
created_at: Date;
|
|
|
7 |
ingredients: string[];
|
8 |
calories: number;
|
9 |
carbs: number;
|
@@ -15,6 +16,7 @@ export interface IMeal {
|
|
15 |
const mealSchema = new Schema({
|
16 |
name: { type: String, required: true, unique: true, dropDups: true },
|
17 |
created_at: { type: Date, default: Date.now() },
|
|
|
18 |
type: {
|
19 |
type: String,
|
20 |
enum: MealType,
|
|
|
4 |
export interface IMeal {
|
5 |
name: string;
|
6 |
created_at: Date;
|
7 |
+
image: string;
|
8 |
ingredients: string[];
|
9 |
calories: number;
|
10 |
carbs: number;
|
|
|
16 |
const mealSchema = new Schema({
|
17 |
name: { type: String, required: true, unique: true, dropDups: true },
|
18 |
created_at: { type: Date, default: Date.now() },
|
19 |
+
image: { type: String, required: true },
|
20 |
type: {
|
21 |
type: String,
|
22 |
enum: MealType,
|
src/common/serializers/meal.serialization.ts
CHANGED
@@ -15,6 +15,10 @@ export class MealSerialization {
|
|
15 |
@SwaggerResponseProperty({ type: "string" })
|
16 |
created_at: Date;
|
17 |
|
|
|
|
|
|
|
|
|
18 |
@Expose()
|
19 |
@SwaggerResponseProperty({ type: ["string"] })
|
20 |
ingredients: any;
|
|
|
15 |
@SwaggerResponseProperty({ type: "string" })
|
16 |
created_at: Date;
|
17 |
|
18 |
+
@Expose()
|
19 |
+
@SwaggerResponseProperty({ type: "string" })
|
20 |
+
image: string;
|
21 |
+
|
22 |
@Expose()
|
23 |
@SwaggerResponseProperty({ type: ["string"] })
|
24 |
ingredients: any;
|
src/common/serializers/mealPopulate.serialization.ts
CHANGED
@@ -17,6 +17,10 @@ export class MealPopulateSerialization {
|
|
17 |
@SwaggerResponseProperty({ type: "string" })
|
18 |
created_at: Date;
|
19 |
|
|
|
|
|
|
|
|
|
20 |
@Expose()
|
21 |
@SwaggerResponseProperty({ type: [IngredientSerialization] })
|
22 |
@Transform(
|
|
|
17 |
@SwaggerResponseProperty({ type: "string" })
|
18 |
created_at: Date;
|
19 |
|
20 |
+
@Expose()
|
21 |
+
@SwaggerResponseProperty({ type: "string" })
|
22 |
+
image: string;
|
23 |
+
|
24 |
@Expose()
|
25 |
@SwaggerResponseProperty({ type: [IngredientSerialization] })
|
26 |
@Transform(
|
src/modules/console/modules/meals/validations/create-meals.validation.ts
CHANGED
@@ -5,6 +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;
|
@@ -24,6 +25,12 @@ export const createMealSchema = createSchema<ICreateMeal>({
|
|
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",
|
|
|
5 |
export interface ICreateMeal {
|
6 |
name: string;
|
7 |
created_at?: Date;
|
8 |
+
image: string;
|
9 |
ingredients: string[];
|
10 |
calories: number;
|
11 |
carbs: number;
|
|
|
25 |
"date.empty": "created_at can not be empty",
|
26 |
}),
|
27 |
|
28 |
+
image: joi.string().empty().required().messages({
|
29 |
+
"string.base": "please enter a valid image",
|
30 |
+
"any.required": "image is required",
|
31 |
+
"string.empty": "image can not be empty",
|
32 |
+
}),
|
33 |
+
|
34 |
calories: joi.number().empty().required().messages({
|
35 |
"number.base": "please enter a valid calories",
|
36 |
"any.required": "calories is required",
|
src/modules/console/modules/meals/validations/update-meals.validation.ts
CHANGED
@@ -5,6 +5,7 @@ import { MealType } from "@common/enums/meal-type.enum";
|
|
5 |
export interface IUpdateMeal {
|
6 |
name?: string;
|
7 |
created_at?: Date;
|
|
|
8 |
ingredients?: [string];
|
9 |
calories?: number;
|
10 |
carbs?: number;
|
@@ -22,6 +23,10 @@ export const updateMealSchema = createSchema<IUpdateMeal>({
|
|
22 |
"date.base": "please enter a valid created_at",
|
23 |
"date.empty": "created_at can not be empty",
|
24 |
}),
|
|
|
|
|
|
|
|
|
25 |
ingredients: joi.array().items(joi.string()).optional().messages({
|
26 |
"array.base": "please enter a valid ingredients",
|
27 |
}),
|
|
|
5 |
export interface IUpdateMeal {
|
6 |
name?: string;
|
7 |
created_at?: Date;
|
8 |
+
image?: string;
|
9 |
ingredients?: [string];
|
10 |
calories?: number;
|
11 |
carbs?: number;
|
|
|
23 |
"date.base": "please enter a valid created_at",
|
24 |
"date.empty": "created_at can not be empty",
|
25 |
}),
|
26 |
+
image: joi.string().empty().optional().messages({
|
27 |
+
"string.base": "please enter a valid image",
|
28 |
+
"string.empty": "image can not be empty",
|
29 |
+
}),
|
30 |
ingredients: joi.array().items(joi.string()).optional().messages({
|
31 |
"array.base": "please enter a valid ingredients",
|
32 |
}),
|
src/resources/meals1.json
DELETED
The diff for this file is too large to render.
See raw diff
|
|
src/resources/meals2.json
DELETED
The diff for this file is too large to render.
See raw diff
|
|
src/seeder/seeders/9-meals.seeder.ts
CHANGED
@@ -21,6 +21,8 @@ export default seederWrapper(Meal, async () => {
|
|
21 |
console.log('preping meals data...')
|
22 |
const data = await Promise.all(dbStore.mealsDataset.map(async (mealJson) => ({
|
23 |
name: mealJson.Name,
|
|
|
|
|
24 |
ingredients: mealJson.RecipeIngredientParts.map(name => ingredientsIds.find(i => i.name === name)._id),
|
25 |
calories: mealJson.Calories,
|
26 |
carbs: mealJson.CarbohydrateContent,
|
|
|
21 |
console.log('preping meals data...')
|
22 |
const data = await Promise.all(dbStore.mealsDataset.map(async (mealJson) => ({
|
23 |
name: mealJson.Name,
|
24 |
+
created_at: new Date(),
|
25 |
+
image: `https://placehold.co/300x400`,
|
26 |
ingredients: mealJson.RecipeIngredientParts.map(name => ingredientsIds.find(i => i.name === name)._id),
|
27 |
calories: mealJson.Calories,
|
28 |
carbs: mealJson.CarbohydrateContent,
|