Spaces:
Running
Running
Merge pull request #88 from Modarb-Ai-Trainer:seeder
Browse filesfeat: Add seeders for user-registered meal plans and meal plans
- src/common/models/meal-plan.model.ts +9 -9
- src/modules/console/modules/meal-plans/validations/create-meal-plan.validation.ts +8 -8
- src/modules/console/modules/meal-plans/validations/update-meal-plan.validation.ts +8 -8
- src/seeder/seeders/10-mealPlan.seeder.ts +29 -0
- src/seeder/seeders/11-mymealPlan.seeder.ts +21 -0
src/common/models/meal-plan.model.ts
CHANGED
@@ -5,10 +5,10 @@ import { FitnessLevel } from "@common/enums/fitness-level.enum";
|
|
5 |
export interface IMealPlan {
|
6 |
image: string;
|
7 |
description: string;
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
title: string;
|
13 |
description: string;
|
14 |
}[];
|
@@ -19,12 +19,12 @@ export interface IMealPlan {
|
|
19 |
}
|
20 |
|
21 |
const mealPlanSchema = new Schema({
|
22 |
-
|
23 |
description: { type: String, required: true },
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
title: { type: String, required: true },
|
29 |
description: { type: String, required: true },
|
30 |
}],
|
|
|
5 |
export interface IMealPlan {
|
6 |
image: string;
|
7 |
description: string;
|
8 |
+
duration: number;
|
9 |
+
level: FitnessLevel;
|
10 |
+
your_journey: string;
|
11 |
+
key_features: {
|
12 |
title: string;
|
13 |
description: string;
|
14 |
}[];
|
|
|
19 |
}
|
20 |
|
21 |
const mealPlanSchema = new Schema({
|
22 |
+
image: { type: String, required: true },
|
23 |
description: { type: String, required: true },
|
24 |
+
duration: { type: Number, required: true },
|
25 |
+
level: { type: String, enum: FitnessLevel, required: true },
|
26 |
+
your_journey: { type: String, required: true },
|
27 |
+
key_features: [{
|
28 |
title: { type: String, required: true },
|
29 |
description: { type: String, required: true },
|
30 |
}],
|
src/modules/console/modules/meal-plans/validations/create-meal-plan.validation.ts
CHANGED
@@ -5,10 +5,10 @@ import { createSchema } from "@helpers/create-schema";
|
|
5 |
export interface ICreateMealPlan {
|
6 |
image: string;
|
7 |
description: string;
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
title: string;
|
13 |
description: string;
|
14 |
}[];
|
@@ -29,22 +29,22 @@ export const CreateMealPlanKeys = {
|
|
29 |
"any.required": "description is required",
|
30 |
"string.empty": "description can not be empty",
|
31 |
}),
|
32 |
-
|
33 |
"number.base": "please enter a valid Duration",
|
34 |
"any.required": "Duration is required",
|
35 |
"number.empty": "Duration can not be empty",
|
36 |
}),
|
37 |
-
|
38 |
"string.base": "please enter a valid Level",
|
39 |
"any.required": "Level is required",
|
40 |
"string.empty": "Level can not be empty",
|
41 |
}),
|
42 |
-
|
43 |
"string.base": "please enter a valid your_Journey",
|
44 |
"any.required": "your_Journey is required",
|
45 |
"string.empty": "your_Journey can not be empty",
|
46 |
}),
|
47 |
-
|
48 |
joi.object({
|
49 |
title: joi.string().empty().required().messages({
|
50 |
"string.base": "please enter a valid title",
|
|
|
5 |
export interface ICreateMealPlan {
|
6 |
image: string;
|
7 |
description: string;
|
8 |
+
duration: number;
|
9 |
+
level: FitnessLevel;
|
10 |
+
your_journey: string;
|
11 |
+
key_features: {
|
12 |
title: string;
|
13 |
description: string;
|
14 |
}[];
|
|
|
29 |
"any.required": "description is required",
|
30 |
"string.empty": "description can not be empty",
|
31 |
}),
|
32 |
+
duration: joi.number().empty().required().messages({
|
33 |
"number.base": "please enter a valid Duration",
|
34 |
"any.required": "Duration is required",
|
35 |
"number.empty": "Duration can not be empty",
|
36 |
}),
|
37 |
+
level: joi.string().empty().required().messages({
|
38 |
"string.base": "please enter a valid Level",
|
39 |
"any.required": "Level is required",
|
40 |
"string.empty": "Level can not be empty",
|
41 |
}),
|
42 |
+
your_journey: joi.string().empty().required().messages({
|
43 |
"string.base": "please enter a valid your_Journey",
|
44 |
"any.required": "your_Journey is required",
|
45 |
"string.empty": "your_Journey can not be empty",
|
46 |
}),
|
47 |
+
key_features: joi.array().required().items(
|
48 |
joi.object({
|
49 |
title: joi.string().empty().required().messages({
|
50 |
"string.base": "please enter a valid title",
|
src/modules/console/modules/meal-plans/validations/update-meal-plan.validation.ts
CHANGED
@@ -6,10 +6,10 @@ import { UpdateUserRegisteredMealPlan } from "modules/users/modules/user-registe
|
|
6 |
export interface IUpdateMealPlan {
|
7 |
image?: string;
|
8 |
description?: string;
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
title?: string;
|
14 |
description?: string;
|
15 |
}[];
|
@@ -30,22 +30,22 @@ export const UpdateMealPlanKeys = {
|
|
30 |
"any.required": "description is required",
|
31 |
"string.empty": "description can not be empty",
|
32 |
}),
|
33 |
-
|
34 |
"number.base": "please enter a valid Duration",
|
35 |
"any.required": "Duration is required",
|
36 |
"number.empty": "Duration can not be empty",
|
37 |
}),
|
38 |
-
|
39 |
"string.base": "please enter a valid Level",
|
40 |
"any.required": "Level is required",
|
41 |
"string.empty": "Level can not be empty",
|
42 |
}),
|
43 |
-
|
44 |
"string.base": "please enter a valid your_Journey",
|
45 |
"any.required": "your_Journey is required",
|
46 |
"string.empty": "your_Journey can not be empty",
|
47 |
}),
|
48 |
-
|
49 |
joi.object({
|
50 |
title: joi.string().empty().optional().messages({
|
51 |
"string.base": "please enter a valid title",
|
|
|
6 |
export interface IUpdateMealPlan {
|
7 |
image?: string;
|
8 |
description?: string;
|
9 |
+
duration?: number;
|
10 |
+
level?: FitnessLevel;
|
11 |
+
your_journey?: string;
|
12 |
+
key_features?: {
|
13 |
title?: string;
|
14 |
description?: string;
|
15 |
}[];
|
|
|
30 |
"any.required": "description is required",
|
31 |
"string.empty": "description can not be empty",
|
32 |
}),
|
33 |
+
duration: joi.number().empty().optional().messages({
|
34 |
"number.base": "please enter a valid Duration",
|
35 |
"any.required": "Duration is required",
|
36 |
"number.empty": "Duration can not be empty",
|
37 |
}),
|
38 |
+
level: joi.string().empty().optional().messages({
|
39 |
"string.base": "please enter a valid Level",
|
40 |
"any.required": "Level is required",
|
41 |
"string.empty": "Level can not be empty",
|
42 |
}),
|
43 |
+
your_journey: joi.string().empty().optional().messages({
|
44 |
"string.base": "please enter a valid your_Journey",
|
45 |
"any.required": "your_Journey is required",
|
46 |
"string.empty": "your_Journey can not be empty",
|
47 |
}),
|
48 |
+
key_features: joi.array().optional().items(
|
49 |
joi.object({
|
50 |
title: joi.string().empty().optional().messages({
|
51 |
"string.base": "please enter a valid title",
|
src/seeder/seeders/10-mealPlan.seeder.ts
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { MealPlan } from "@common/models/meal-plan.model";
|
2 |
+
import { Meal } from "@common/models/meal.model";
|
3 |
+
import { seederWrapper } from "seeder/helpers/seeder-wrapper";
|
4 |
+
import { FitnessLevel } from "@common/enums/fitness-level.enum";
|
5 |
+
|
6 |
+
export default seederWrapper(MealPlan, async () => {
|
7 |
+
// 10 mealPlans
|
8 |
+
await Promise.all(Array.from({ length: 10 }, (_, i) => i).map(async function (i) {
|
9 |
+
const meals = await Meal.find().limit(35).lean();
|
10 |
+
|
11 |
+
let o = {
|
12 |
+
image: `https://placehold.co/300x400`,
|
13 |
+
description: 'This is a description of the meal plan.',
|
14 |
+
duration: 7,
|
15 |
+
level: [FitnessLevel.BEGINNER, FitnessLevel.INTERMEDIATE, FitnessLevel.ADVANCED][i % 3],
|
16 |
+
your_journey: 'This is your journey description.',
|
17 |
+
key_features: [
|
18 |
+
{ title: 'Feature 1', description: 'Description for feature 1' },
|
19 |
+
{ title: 'Feature 2', description: 'Description for feature 2' },
|
20 |
+
],
|
21 |
+
days: Array.from({ length: 7 }, (_, i) => ({
|
22 |
+
day_number: i + 1,
|
23 |
+
meals: meals.slice(i * 5, i * 5 + 5),
|
24 |
+
})),
|
25 |
+
}
|
26 |
+
|
27 |
+
await MealPlan.create(o);
|
28 |
+
}))
|
29 |
+
})
|
src/seeder/seeders/11-mymealPlan.seeder.ts
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { UserRegisteredMealPlan } from "@common/models/user-registered-meal-plan.model";
|
2 |
+
import { MealPlan } from "@common/models/meal-plan.model";
|
3 |
+
import { seederWrapper } from "seeder/helpers/seeder-wrapper";
|
4 |
+
import { User } from "@common/models/user.model";
|
5 |
+
|
6 |
+
export default seederWrapper(UserRegisteredMealPlan, async () => {
|
7 |
+
const users = await User.find().lean();
|
8 |
+
|
9 |
+
await Promise.all(users.map(async (user: any) => {
|
10 |
+
const mealPlans = await MealPlan.find().lean();
|
11 |
+
let index = Math.floor(Math.random() * mealPlans.length);
|
12 |
+
const userRegisteredMealPlan = new UserRegisteredMealPlan({
|
13 |
+
user: user._id,
|
14 |
+
meal_plan: mealPlans[index]._id,
|
15 |
+
is_active: true,
|
16 |
+
days: mealPlans[index].days
|
17 |
+
});
|
18 |
+
await userRegisteredMealPlan.save();
|
19 |
+
}));
|
20 |
+
|
21 |
+
});
|