File size: 1,731 Bytes
cbdd38a
 
 
 
 
 
 
 
 
 
 
 
 
437a7ee
cbdd38a
 
 
 
 
 
889c2f1
cbdd38a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { ExerciseType } from "@common/enums/exercise-type.enum";
import { Equipment } from "@common/models/equipment.model";
import { Exercise, IExercise } from "@common/models/exercise.model";
import { Muscle } from "@common/models/muscle.model";
import { dbStore } from "seeder/helpers/db-store";
import { IExerciseCSV } from "seeder/helpers/load-exercises-dataset";
import { seederWrapper } from "seeder/helpers/seeder-wrapper";

export default seederWrapper(Exercise, async () => {
  console.log('preparing exercises data... (this may take a while)');
  const data = await Promise.all(dbStore.excerisesDataset.map(async function (e: IExerciseCSV) {
    return {
      name: e.name,
      category: e.bodyPart,
      exerciseType: e.type,
      ...(
        e.type === ExerciseType.WEIGHT && 
        {
          reps: Math.floor(Math.random() * 10),
          sets: e.sets,
          duration: 0,
        } 
        ||
        {
          duration: Math.floor(Math.random() * 100),
        }
      ),
      expectedDurationRange: {
        min: Math.floor(Math.random() * 10),
        max: 10 + Math.floor(Math.random() * 10),
      },
      instructions: "Do this exercise",
      benefits: "You will get stronger",
      targetMuscles: {
        primary: (await Muscle.findOne({ name: e.target }).exec())._id,
        secondary: (await Muscle.findOne({ name: e.target }).exec())._id,
      },
      equipments: [(await Equipment.findOne({name: e.equipment}).exec())._id],
      coverImage: "https://placehold.co/600x400",
      media: {
        type: 'image',
        url: "https://placehold.co/600x400",
      }
    } satisfies IExercise;
  }))
  console.log('inserting exercises...');
  await Exercise.insertMany(data);
})