-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-dates.js
More file actions
69 lines (58 loc) · 2.08 KB
/
update-dates.js
File metadata and controls
69 lines (58 loc) · 2.08 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
async function updateWorkoutDates() {
try {
const today = new Date();
// Get all workouts with old dates
const workouts = await prisma.workout.findMany({
where: {
routine: {
user_id: "user_2mmt2YuDA7jJ1gQn0J8a8nicy6n",
},
},
include: {
Set: true,
},
});
console.log("Found workouts:", workouts.length);
for (const workout of workouts) {
console.log(`Updating workout ${workout.workout_name} from ${workout.date} to ${today}`);
// Update the workout date
await prisma.workout.update({
where: { workout_id: workout.workout_id },
data: { date: today },
});
// Update all associated sets to today as well
await prisma.set.updateMany({
where: { workout_id: workout.workout_id },
data: { date: today },
});
}
console.log("All workout dates updated to today!");
// Show the updated workouts
const updatedWorkouts = await prisma.workout.findMany({
where: {
routine: {
user_id: "user_2mmt2YuDA7jJ1gQn0J8a8nicy6n",
},
},
include: {
Set: true,
},
});
console.log("Updated workouts:");
updatedWorkouts.forEach(workout => {
console.log(`- ${workout.workout_name}: ${workout.date}, Total calories: ${workout.total_calories_burned}`);
workout.Set.forEach((set, index) => {
console.log(
` Set ${index + 1}: ${set.set_reps} reps @ ${set.set_weight}kg, Calories: ${set.calories_burned}`
);
});
});
} catch (error) {
console.error("Error updating workout dates:", error);
} finally {
await prisma.$disconnect();
}
}
updateWorkoutDates();