Skip to content

Seminar punch: ask caller when the lesson was already reported (1 = add another, 2 = delete previous) - #191

Closed
buzz-code wants to merge 2 commits into
mainfrom
seminar-lesson-duplicate-guard
Closed

buzz-code wants to merge 2 commits into
mainfrom
seminar-lesson-duplicate-guard

Conversation

@buzz-code

@buzz-code buzz-code commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

Problem

Client report (שיפי, Hadasa): girls validated the same lesson multiple times — "הבנות תיקפו כל שיעור כמה פעמים". The seminar attendance IVR flow had no duplicate check on the lesson punch.

Fix

In processSeminarAttendanceCall (server/src/yemot-handler.service.ts), the klass roster is fetched first (empty roster → hang up with SEMINAR.NO_STUDENTS_IN_KLASS), and when the resolved schedule sets a lessonReferenceId, the handler checks AttReport for existing rows for the same user + klass + teacher + lesson + today's date (Israel date). If found, the caller is asked:

  • 1 — add another lesson: flow continues, new rows are saved on top of the previous report.
  • 2 — delete the previous: in one transaction, all matching rows for that lesson/klass/teacher/date are deleted (one row per student), then their ReportGroupSessions are deleted once no remaining AttReport row references them, and each session's ReportGroup is deleted once no remaining session references it — a confirmation message is sent, then the new report is saved normally (creating its own fresh group/session as saveSeminarAttendance already does).

If no existing row is found, the flow is unchanged. Calls with no schedule match (no lessonReferenceId) are unchanged — re-reporting the same klass on the same day without a schedule still works (existing test kept passing).

Queries are keyed on existing columns and ride the existing att_teacher_lesson_date_idx (teacherReferenceId, lessonReferenceId, reportDate) — no schema migration needed.

Change is local to server/src/; the server/shared and client/shared submodules are untouched.

Texts seeding (migration)

The two new IVR texts are seeded automatically by migration 1789600000000-UpdateYemotTextsSeminarDuplicateLesson (inserts for user_id 0, following the existing UpdateYemotTexts* migration pattern; down deletes them) — no manual DB setup needed:

name value
SEMINAR.DUPLICATE_LESSON_PROMPT השיעור כבר תוקף. הקישי 1 להוספת שיעור נוסף, 2 למחיקת הקודם
SEMINAR.DUPLICATE_LESSON_DELETED הדיווח הקודם נמחק

Tests

Seminar block in yemot-handler.service.test.ts (26/26 green):

  • add (answer 1) — 3 prior rows seeded; previous rows kept, 3 new AttReport rows saved.
  • delete (answer 2) — seeds the full prior report (3 rows, one per student, one with absCount: 1, all referencing a ReportGroupSession) plus a still-referenced session/row for another lesson; runs the flow against the real in-memory DataSource and asserts the complete post-run state: prior rows gone, exactly 3 fresh rows (students 101–103, absCount 0), the now-unreferenced session deleted, its fully-unused ReportGroup deleted, while the still-referenced session and its group survive.

The rest of the suite shows the same pre-existing failures as the origin/main baseline (verified identical failure list with/without the change).

…rior report

Girls were punching the same lesson multiple times. When the resolved
lesson+klass+teacher+date already has AttReport rows, the caller now gets
a prompt: 1 = add another lesson (new rows saved on top), 2 = delete the
previous rows for that lesson before the new report is saved.

New IVR text keys (need manual DB setup, see PR):
- SEMINAR.DUPLICATE_LESSON_PROMPT
- SEMINAR.DUPLICATE_LESSON_DELETED

Queries ride the existing att_teacher_lesson_date_idx - no migration.
Copilot AI lite review requested due to automatic review settings September 16, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Address the empty-roster ordering, session/group cleanup, and production text-seeding findings.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR adds duplicate scheduled-lesson handling to the seminar attendance IVR flow.

Changes:

  • Detects existing lesson reports and offers add/delete choices.
  • Deletes matching reports before saving a fresh report.
  • Adds duplicate-flow scenarios and seminar text fixtures.
File summaries
File Summary Review findings
server/src/yemot-handler.service.ts Duplicate detection, deletion, and prompts Moderate (2 votes): perform the empty-roster guard before duplicate deletion. Moderate (2 votes): clean up associated report sessions/groups when deleting reports. Moderate (2 votes): provide production text rows through migration or deployment seed.
server/src/yemot-handler.service.test.ts Add/delete duplicate lesson scenarios Nit (1 vote): seed multiple prior rows and assert complete bulk-deletion state.
Review details

Suppressed comments (1)

server/src/yemot-handler.service.test.ts:638

  • Only one prior AttReport row is seeded here, so this does not verify the promised bulk deletion of one row per student; a regression that deletes only one matching row still passes. Seed multiple matching rows and assert complete post-run state rather than relying on the runner's seed-count subtraction.
        .seed('AttReport', [
          { id: 910, userId: 1, studentReferenceId: 101, klassReferenceId: 286, teacherReferenceId: 1, lessonReferenceId: 700, reportDate: today, absCount: 1 },
        ]);
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread server/src/yemot-handler.service.ts Outdated
Comment on lines +120 to +122
if (lessonReferenceId) {
await this.handleLessonDuplicate(teacher, klass, lessonReferenceId);
}
});
if (!existing) return;

const choice = await this.askForInputByKey('SEMINAR.DUPLICATE_LESSON_PROMPT', undefined, {
Comment thread server/src/yemot-handler.service.ts Outdated
Comment on lines +153 to +159
await this.dataSource.getRepository(AttReport).delete({
userId: this.user.id,
klassReferenceId: klass.id,
teacherReferenceId: teacher.id,
lessonReferenceId,
reportDate,
});
…s migration, stronger delete test

- Check the klass roster (hang up when empty) before the duplicate prompt,
  so an empty-klass call can no longer delete prior rows.
- On delete (option 2): remove the prior AttReport rows, then drop their
  ReportGroupSessions once no report row references them, and their
  ReportGroups once no session references them - all in one transaction.
- Seed the two new texts via migration instead of manual DB setup
  (UpdateYemotTextsSeminarDuplicateLesson, user_id 0).
- Delete-path test now seeds the full prior report (one row per student,
  one with absCount 1, two report sessions) and asserts the complete
  post-run DB state instead of the runner's seed-count arithmetic.
@buzz-code buzz-code closed this Sep 16, 2026
buzz-code pushed a commit that referenced this pull request Sep 16, 2026
Adds the duplicate-lesson-punch handling in processSeminarAttendanceCall
(ask 1=add another, 2=delete previous, with cascade cleanup of now-unused
ReportGroupSession/ReportGroup rows) plus its test coverage, alongside
the previously added texts migration with a real timestamp.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WER1oSuN8tCQTNRU73Mi89
buzz-code added a commit that referenced this pull request Sep 17, 2026
Seminar duplicate-lesson guard (from PR #191, real migration timestamp)
TziporaStern pushed a commit to TziporaStern/react-admin-nestjs that referenced this pull request Oct 17, 2026
Same texts as PR buzz-code#191's migration, filename/class timestamped with
actual Date.now() instead of a rounded placeholder.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WER1oSuN8tCQTNRU73Mi89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants