Hozifa Elgharbawy commited on
Commit
fd459a6
·
1 Parent(s): 889c2f1

Add workout and user registered workout seeders

Browse files
src/seeder/seeders/6-workout.seeder.ts ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Workout } from "@common/models/workout.model";
2
+ import { seederWrapper } from "seeder/helpers/seeder-wrapper";
3
+ import { Exercise } from "@common/models/exercise.model";
4
+ import { FitnessLevel } from "@common/enums/fitness-level.enum";
5
+ import { FitnessGoal } from "@common/enums/fitness-goal.enum";
6
+ import { Place } from "@common/enums/place.enum";
7
+
8
+ export default seederWrapper(Workout, async () => {
9
+ // 10 workouts
10
+ await Promise.all(Array.from({ length: 10 }, (_, i) => i).map(async function (i) {
11
+ const exercisesDuration = await Exercise.find(
12
+ {
13
+ duration: { $gt: 0 },
14
+ sets: { $exists: false },
15
+ reps: { $exists: false },
16
+ }
17
+ ).limit(4).skip(i*4).lean();
18
+
19
+ const exercisesReps = await Exercise.find(
20
+ {
21
+ duration: 0,
22
+ sets: { $gt: 0 },
23
+ reps: { $gt: 0 }
24
+ }
25
+ ).limit(4).skip(i*4).lean();
26
+
27
+ const o = {
28
+ name: `Workout - ${i}`,
29
+ description: `Workout - ${i} description`,
30
+ type: 'Equipment Diversity',
31
+ image: `https://placehold.co/300x400`,
32
+ fitness_level: [FitnessLevel.BEGINNER, FitnessLevel.INTERMEDIATE, FitnessLevel.ADVANCED][i % 3],
33
+ fitness_goal: [FitnessGoal.LOSE_WEIGHT, FitnessGoal.GAIN_MUSCLE, FitnessGoal.GET_FITTER][i % 3],
34
+ place: [Place.GYM, Place.HOME][i % 2],
35
+ min_per_day: 30,
36
+ total_number_days: 4,
37
+ template_weeks: [
38
+ {
39
+ week_number: 1,
40
+ week_name: 'Week 1',
41
+ week_description: 'Week 1 description',
42
+ days: [
43
+ {
44
+ day_number: 1,
45
+ total_number_exercises: 2,
46
+ day_type: 'full_body',
47
+ exercises: [
48
+ exercisesDuration.slice(0, 1).map((e: any) => e._id),
49
+ exercisesReps.slice(0, 1).map((e: any) => e._id)
50
+ ]
51
+ },
52
+ {
53
+ day_number: 2,
54
+ total_number_exercises: 2,
55
+ day_type: 'full_body',
56
+ exercises: [
57
+ exercisesDuration.slice(1, 2).map((e: any) => e._id),
58
+ exercisesReps.slice(1, 2).map((e: any) => e._id)
59
+ ]
60
+ },
61
+ ]
62
+ },
63
+ {
64
+ week_number: 2,
65
+ week_name: 'Week 2',
66
+ week_description: 'Week 2 description',
67
+ days: [
68
+ {
69
+ day_number: 1,
70
+ total_number_exercises: 2,
71
+ day_type: 'full_body',
72
+ exercises: [
73
+ exercisesDuration.slice(2, 3).map((e: any) => e._id),
74
+ exercisesReps.slice(2, 3).map((e: any) => e._id)
75
+ ]
76
+ },
77
+ {
78
+ day_number: 2,
79
+ total_number_exercises: 2,
80
+ day_type: 'full_body',
81
+ exercises: [
82
+ exercisesDuration.slice(3, 4).map((e: any) => e._id),
83
+ exercisesReps.slice(3, 4).map((e: any) => e._id)
84
+ ]
85
+ },
86
+ ]
87
+ }
88
+ ]
89
+ };
90
+ await Workout.create(o);
91
+ }))
92
+ })
src/seeder/seeders/7-myWorkout.seeder.ts ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { UserRegisteredWorkout } from "@common/models/user-registered-workout.model";
2
+ import { seederWrapper } from "seeder/helpers/seeder-wrapper";
3
+ import { User } from "@common/models/user.model";
4
+ import { Workout } from "@common/models/workout.model";
5
+
6
+ export default seederWrapper(UserRegisteredWorkout, async () => {
7
+ const users = await User.find().lean();
8
+
9
+ await Promise.all(users.map(async (user: any) => {
10
+ const workouts = await Workout.find({
11
+ fitness_level: user.fitness_level,
12
+ fitness_goal: user.preferences.fitness_goal,
13
+ }).lean();
14
+ let index = Math.floor(Math.random() * workouts.length);
15
+ const userRegisteredWorkout = new UserRegisteredWorkout({
16
+ user: user._id,
17
+ workout: workouts[index]._id,
18
+ is_active: true,
19
+ weeks: workouts[index].template_weeks
20
+ });
21
+ await userRegisteredWorkout.save();
22
+ }));
23
+
24
+ });
25
+