CognxSafeTrack commited on
Commit
aa52c48
·
1 Parent(s): 4a79a6d

fix(syntax): resolve unbalanced braces and scoping in WhatsAppService

Browse files
Files changed (1) hide show
  1. apps/api/src/services/whatsapp.ts +31 -40
apps/api/src/services/whatsapp.ts CHANGED
@@ -1,5 +1,5 @@
1
  import { prisma } from './prisma';
2
- import { scheduleMessage, enrollUser, whatsappQueue, scheduleInteractiveButtons, scheduleInteractiveList } from './queue';
3
 
4
  export class WhatsAppService {
5
  private static normalizeCommand(text: string): string {
@@ -299,51 +299,42 @@ export class WhatsAppService {
299
  return;
300
  }
301
  }
302
- }
303
 
304
- // Handle daily response (Fallback if no PENDING found earlier)
305
- console.log(`${traceId} User ${user.id} fallback daily response to day ${activeEnrollment.currentDay}`);
306
- await prisma.response.create({
307
- data: {
308
- enrollmentId: activeEnrollment.id,
309
- userId: user.id,
310
- dayNumber: activeEnrollment.currentDay,
311
- content: text
312
- }
313
- });
314
-
315
- // If we are here, it means pendingProgress (logic #2) was NOT found.
316
- // But we should probably check if it SHOULD have been pending (auto-fix state)
317
- const trackDay = await prisma.trackDay.findFirst({
318
- where: { trackId: activeEnrollment.trackId, dayNumber: activeEnrollment.currentDay }
319
- });
320
 
321
- if (trackDay && text.length > 3) {
322
- // Trigger feedback anyway to be safe!
323
- await whatsappQueue.add('generate-feedback', {
324
- userId: user.id,
325
- text,
326
- trackId: activeEnrollment.trackId,
327
- trackDayId: trackDay.id,
328
- exercisePrompt: trackDay.exercisePrompt || '',
329
- lessonText: trackDay.lessonText || '',
330
- exerciseCriteria: trackDay.exerciseCriteria,
331
- enrollmentId: activeEnrollment.id,
332
- currentDay: activeEnrollment.currentDay,
333
- language: user.language
334
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  return;
336
  }
337
 
338
- await scheduleMessage(user.id, user.language === 'WOLOF'
339
- ? "Baax na ! Yónnee *SUITE* ngir dem ci kanam walla tontul laaj bi ci kaw."
340
- : "✅ Message reçu ! Envoie *SUITE* pour avancer ou réponds à l'exercice ci-dessus."
341
- );
342
- return;
343
- }
344
-
345
- // 4. Default: fallback for generic unknown messages
346
- console.log(`${traceId} Unknown command from onboarded user ${ user.id }: "${normalizedText}"`);
347
  await scheduleMessage(user.id, user.language === 'WOLOF'
348
  ? "Bañ ma dégg. Yónnee *INSCRIPTION* ngir tàmbalee ci kanam walla bind *SUITE*."
349
  : "Je n'ai pas compris. Envoie *INSCRIPTION* pour recommencer ou *SUITE* pour avancer."
 
1
  import { prisma } from './prisma';
2
+ import { scheduleMessage, enrollUser, whatsappQueue, scheduleInteractiveButtons } from './queue';
3
 
4
  export class WhatsAppService {
5
  private static normalizeCommand(text: string): string {
 
299
  return;
300
  }
301
  }
 
302
 
303
+ // Handle daily response (Fallback if no PENDING found earlier)
304
+ console.log(`${traceId} User ${user.id} fallback daily response to day ${activeEnrollment.currentDay}`);
305
+ await prisma.response.create({
306
+ data: {
307
+ enrollmentId: activeEnrollment.id,
308
+ userId: user.id,
309
+ dayNumber: activeEnrollment.currentDay,
310
+ content: text
311
+ }
312
+ });
 
 
 
 
 
 
313
 
314
+ const trackDayFallback = await prisma.trackDay.findFirst({
315
+ where: { trackId: activeEnrollment.trackId, dayNumber: activeEnrollment.currentDay }
 
 
 
 
 
 
 
 
 
 
 
316
  });
317
+
318
+ if (trackDayFallback && text.length > 3) {
319
+ await whatsappQueue.add('generate-feedback', {
320
+ userId: user.id, text, trackId: activeEnrollment.trackId, trackDayId: trackDayFallback.id,
321
+ exercisePrompt: trackDayFallback.exercisePrompt || '', lessonText: trackDayFallback.lessonText || '',
322
+ exerciseCriteria: trackDayFallback.exerciseCriteria,
323
+ enrollmentId: activeEnrollment.id, currentDay: activeEnrollment.currentDay,
324
+ totalDays: activeEnrollment.track.duration, language: user.language
325
+ });
326
+ return;
327
+ }
328
+
329
+ await scheduleMessage(user.id, user.language === 'WOLOF'
330
+ ? "Baax na ! Yónnee *SUITE* ngir dem ci kanam walla tontul laaj bi ci kaw."
331
+ : "✅ Message reçu ! Envoie *SUITE* pour avancer ou réponds à l'exercice ci-dessus."
332
+ );
333
  return;
334
  }
335
 
336
+ // 4. Default: fallback for generic unknown messages (not in onboarding, not in active enrollment)
337
+ console.log(`${traceId} Unknown command from user ${user.id}: "${normalizedText}"`);
 
 
 
 
 
 
 
338
  await scheduleMessage(user.id, user.language === 'WOLOF'
339
  ? "Bañ ma dégg. Yónnee *INSCRIPTION* ngir tàmbalee ci kanam walla bind *SUITE*."
340
  : "Je n'ai pas compris. Envoie *INSCRIPTION* pour recommencer ou *SUITE* pour avancer."