File size: 915 Bytes
fd459a6
 
 
 
 
 
 
 
 
 
 
 
 
75f3dfb
fd459a6
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { UserRegisteredWorkout } from "@common/models/user-registered-workout.model";
import { seederWrapper } from "seeder/helpers/seeder-wrapper";
import { User } from "@common/models/user.model";
import { Workout } from "@common/models/workout.model";

export default seederWrapper(UserRegisteredWorkout, async () => {
  const users = await User.find().lean();

  await Promise.all(users.map(async (user: any) => {
    const workouts = await Workout.find({
      fitness_level: user.fitness_level,
      fitness_goal: user.preferences.fitness_goal,
    }).lean();
    if (workouts.length === 0) return;
    let index = Math.floor(Math.random() * workouts.length);
    const userRegisteredWorkout = new UserRegisteredWorkout({
      user: user._id,
      workout: workouts[index]._id,
      is_active: true,
      weeks: workouts[index].template_weeks
    });
    await userRegisteredWorkout.save();
  }));

});