CognxSafeTrack commited on
Commit ·
d92dbd4
1
Parent(s): b0907ad
fix(scripts): move reset script to apps/api to fix IDE error
Browse files
apps/api/src/scripts/reset-user.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { PrismaClient } from '@repo/database';
|
| 2 |
+
|
| 3 |
+
const prisma = new PrismaClient();
|
| 4 |
+
|
| 5 |
+
async function main() {
|
| 6 |
+
const userId = 'acfe7f9c-d8df-4d0d-9eb2-47ef9c716b63';
|
| 7 |
+
|
| 8 |
+
console.log(`[CLEANUP] Resetting progress for User ${userId}`);
|
| 9 |
+
|
| 10 |
+
// Find the enrollment to get the current day
|
| 11 |
+
const enrollment = await prisma.enrollment.findFirst({
|
| 12 |
+
where: { userId, status: 'ACTIVE' },
|
| 13 |
+
include: { track: true }
|
| 14 |
+
});
|
| 15 |
+
|
| 16 |
+
if (enrollment) {
|
| 17 |
+
console.log(`[CLEANUP] Found active enrollment: ${enrollment.trackId} (Day ${enrollment.currentDay})`);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
const progress = await prisma.userProgress.findFirst({
|
| 21 |
+
where: { userId }
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
if (progress) {
|
| 25 |
+
await prisma.userProgress.update({
|
| 26 |
+
where: { id: progress.id },
|
| 27 |
+
data: {
|
| 28 |
+
exerciseStatus: 'PENDING',
|
| 29 |
+
}
|
| 30 |
+
});
|
| 31 |
+
console.log(`[CLEANUP] ✅ UserProgress reset to PENDING.`);
|
| 32 |
+
} else {
|
| 33 |
+
console.log(`[CLEANUP] ⚠️ No progress found for user.`);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// Optional: Delete latest response for the current day
|
| 37 |
+
if (enrollment) {
|
| 38 |
+
const deleted = await prisma.response.deleteMany({
|
| 39 |
+
where: {
|
| 40 |
+
userId,
|
| 41 |
+
enrollmentId: enrollment.id,
|
| 42 |
+
dayNumber: enrollment.currentDay
|
| 43 |
+
}
|
| 44 |
+
});
|
| 45 |
+
console.log(`[CLEANUP] 🗑️ Deleted ${deleted.count} existing response(s) for Day ${enrollment.currentDay}.`);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
await prisma.$disconnect();
|
| 49 |
+
console.log(`[CLEANUP] Done. Ready for re-test.`);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
main().catch(console.error);
|