Spaces:
Running
Running
Hozifa Elgharbawy
commited on
Commit
·
54372bf
1
Parent(s):
01b0d9b
seeder
Browse files
src/seeder/seeders/012-activities.seeder.ts
CHANGED
|
@@ -10,27 +10,31 @@ export default seederWrapper(Activity, async () => {
|
|
| 10 |
const users = await User.find().lean();
|
| 11 |
const exercises = await Exercise.find().lean();
|
| 12 |
const meals = await Meal.find().lean();
|
| 13 |
-
const today = moment(
|
| 14 |
await Promise.all(users.map(async (user: any) => {
|
| 15 |
for (let i = 0; i < 10; i++) {
|
| 16 |
const createdAt = today.clone().subtract(i, 'days').toDate();
|
|
|
|
| 17 |
// Create 10 exercise activities
|
| 18 |
-
let
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
// Create 10 meal activities
|
| 27 |
-
let
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
}));
|
| 36 |
});
|
|
|
|
| 10 |
const users = await User.find().lean();
|
| 11 |
const exercises = await Exercise.find().lean();
|
| 12 |
const meals = await Meal.find().lean();
|
| 13 |
+
const today = moment(); // Use the current date
|
| 14 |
await Promise.all(users.map(async (user: any) => {
|
| 15 |
for (let i = 0; i < 10; i++) {
|
| 16 |
const createdAt = today.clone().subtract(i, 'days').toDate();
|
| 17 |
+
const random = Math.floor(5 + Math.random() * 15);
|
| 18 |
// Create 10 exercise activities
|
| 19 |
+
for (let j = 0; j < random; j++) {
|
| 20 |
+
let exerciseActivity = new Activity({
|
| 21 |
+
user_id: user._id,
|
| 22 |
+
activity_type: ActivityType.EXERCISE,
|
| 23 |
+
related_id: exercises[Math.floor(Math.random() * exercises.length)]._id,
|
| 24 |
+
created_at: createdAt
|
| 25 |
+
});
|
| 26 |
+
await exerciseActivity.save();
|
| 27 |
+
}
|
| 28 |
// Create 10 meal activities
|
| 29 |
+
for (let j = 0; j < random; j++) {
|
| 30 |
+
let mealActivity = new Activity({
|
| 31 |
+
user_id: user._id,
|
| 32 |
+
activity_type: ActivityType.MEAL,
|
| 33 |
+
related_id: meals[Math.floor(Math.random() * meals.length)]._id,
|
| 34 |
+
created_at: createdAt
|
| 35 |
+
});
|
| 36 |
+
await mealActivity.save();
|
| 37 |
+
}
|
| 38 |
}
|
| 39 |
}));
|
| 40 |
});
|