Spaces:
Sleeping
Sleeping
File size: 1,767 Bytes
01b0d9b 54372bf 01b0d9b 54372bf 01b0d9b 54372bf 01b0d9b 54372bf 01b0d9b |
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 |
import { Activity } from "@common/models/activity.model";
import { seederWrapper } from "seeder/helpers/seeder-wrapper";
import { User } from "@common/models/user.model";
import { Exercise } from "@common/models/exercise.model";
import { Meal } from "@common/models/meal.model";
import { ActivityType } from "@common/enums/activity-type.enum";
import moment from "moment";
export default seederWrapper(Activity, async () => {
const users = await User.find().lean();
const exercises = await Exercise.find().lean();
const meals = await Meal.find().lean();
const today = moment(); // Use the current date
await Promise.all(users.map(async (user: any) => {
for (let i = 0; i < 10; i++) {
const createdAt = today.clone().subtract(i, 'days').toDate();
const random = Math.floor(5 + Math.random() * 15);
// Create 10 exercise activities
for (let j = 0; j < random; j++) {
let exerciseActivity = new Activity({
user_id: user._id,
activity_type: ActivityType.EXERCISE,
related_id: exercises[Math.floor(Math.random() * exercises.length)]._id,
created_at: createdAt
});
await exerciseActivity.save();
}
// Create 10 meal activities
for (let j = 0; j < random; j++) {
let mealActivity = new Activity({
user_id: user._id,
activity_type: ActivityType.MEAL,
related_id: meals[Math.floor(Math.random() * meals.length)]._id,
created_at: createdAt
});
await mealActivity.save();
}
}
}));
});
|