CognxSafeTrack commited on
Commit
11f5170
Β·
1 Parent(s): 973438e

fix(audit): ensure badges are only awarded on successful exercises

Browse files
Files changed (1) hide show
  1. apps/whatsapp-worker/src/index.ts +23 -23
apps/whatsapp-worker/src/index.ts CHANGED
@@ -147,27 +147,11 @@ const worker = new Worker('whatsapp-queue', async (job: Job) => {
147
  }
148
  }
149
 
150
- // πŸ… WORKER WOW: Award Badge πŸ…
151
- const trackDayBadges = (trackDay as any)?.badges as string[] || [];
152
  const currentProgress = await prisma.userProgress.findUnique({ where: { id: pendingProgressId } });
153
  const currentBadges = ((currentProgress as any)?.badges as string[]) || [];
154
-
155
  let updatedBadges = [...currentBadges];
156
- for (const b of trackDayBadges) {
157
- if (!updatedBadges.includes(b)) updatedBadges.push(b);
158
- }
159
-
160
- await prisma.userProgress.update({
161
- where: { id: pendingProgressId },
162
- data: {
163
- exerciseStatus: 'COMPLETED',
164
- score: { increment: 1 },
165
- badges: updatedBadges
166
- } as any
167
- });
168
-
169
- // 🌟 Adaptive Pedagogy: Dynamic Remediation Logic v1.0 🌟
170
- let nextDay = currentDay + 1;
171
 
172
  if (feedbackData?.isQualified === false) {
173
  const remediationDay = (exerciseCriteria as any)?.remediation?.dayNumber;
@@ -178,11 +162,27 @@ const worker = new Worker('whatsapp-queue', async (job: Job) => {
178
  console.log(`[WORKER] Exercise not qualified but no remediation day defined. Staying on Day ${currentDay}.`);
179
  nextDay = currentDay;
180
  }
181
- }
182
- // If we were in a remediation day (fractional) and now qualified -> move to next integer day
183
- else if (currentDay % 1 !== 0 && feedbackData?.isQualified !== false) {
184
- nextDay = Math.floor(currentDay) + 1;
185
- console.log(`[WORKER] Remediation successful for User ${userId}. Moving to Day ${nextDay}.`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  }
187
 
188
  await prisma.enrollment.updateMany({
 
147
  }
148
  }
149
 
150
+ // 🌟 Adaptive Pedagogy: Dynamic Remediation Logic v1.0 🌟
151
+ let nextDay = currentDay + 1;
152
  const currentProgress = await prisma.userProgress.findUnique({ where: { id: pendingProgressId } });
153
  const currentBadges = ((currentProgress as any)?.badges as string[]) || [];
 
154
  let updatedBadges = [...currentBadges];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
  if (feedbackData?.isQualified === false) {
157
  const remediationDay = (exerciseCriteria as any)?.remediation?.dayNumber;
 
162
  console.log(`[WORKER] Exercise not qualified but no remediation day defined. Staying on Day ${currentDay}.`);
163
  nextDay = currentDay;
164
  }
165
+ } else {
166
+ // Success! Award Badges & Mark Completed
167
+ const trackDayBadges = (trackDay as any)?.badges as string[] || [];
168
+ for (const b of trackDayBadges) {
169
+ if (!updatedBadges.includes(b)) updatedBadges.push(b);
170
+ }
171
+
172
+ await prisma.userProgress.update({
173
+ where: { id: pendingProgressId },
174
+ data: {
175
+ exerciseStatus: 'COMPLETED',
176
+ score: { increment: 1 },
177
+ badges: updatedBadges
178
+ } as any
179
+ });
180
+
181
+ // If we were in a remediation day (fractional) -> move to next integer day
182
+ if (currentDay % 1 !== 0) {
183
+ nextDay = Math.floor(currentDay) + 1;
184
+ console.log(`[WORKER] Remediation successful for User ${userId}. Moving to Day ${nextDay}.`);
185
+ }
186
  }
187
 
188
  await prisma.enrollment.updateMany({