Skip to content

Seminar duplicate-lesson guard (from PR #191, real migration timestamp) - #192

Merged
buzz-code merged 3 commits into
mainfrom
claude/brave-clarke-34dapr
Sep 17, 2026
Merged

buzz-code merged 3 commits into
mainfrom
claude/brave-clarke-34dapr

Conversation

@buzz-code

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

Copy link
Copy Markdown
Owner

Problem

Client report: girls validated the same lesson multiple times. The seminar attendance IVR flow had no duplicate check on the lesson punch.

Fix

In processSeminarAttendanceCall, once a lessonReferenceId is resolved from the schedule, askDuplicateLessonChoice immediately checks AttReport for an existing row for the same user + klass + teacher + lesson + today (Israel date), and if found asks the caller right away:

  • 1 — add another lesson.
  • 2 — delete the previous.

The choice is only remembered at that point. The actual delete of the prior AttReport rows happens later, inside saveSeminarAttendance's transaction, immediately before the fresh rows are inserted — so the old report isn't touched until the new one is ready to replace it in the same atomic operation, and the "previous report deleted" confirmation is sent only once that's actually done.

No existing row → flow unchanged. No schedule match (no lessonReferenceId) → flow unchanged.

Dropped from PR #191: the cascade cleanup that also deleted now-unreferenced ReportGroupSession/ReportGroup rows. It only checked AttReport before deleting a session, but Grade.reportGroupSessionId also FKs to report_group_sessions with ON DELETE NO ACTION — if any Grade row referenced that session, the delete would throw and abort the whole transaction mid-call. Orphaned group/session rows are harmless (nothing left points at them), so it's simpler and safer to just leave them and only delete the duplicate AttReport rows.

Texts migration

Seeds the two new IVR texts via 1789587905258-UpdateYemotTextsSeminarDuplicateLesson.ts — same content as #191's migration, but with a real Date.now() timestamp instead of a rounded placeholder.

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

Tests

Test file adapted from #191: "add" (answer 1) unchanged; "delete" (answer 2) now asserts the prior AttReport rows for that lesson are gone and fresh rows are saved, while ReportGroup/ReportGroupSession rows are left untouched (no cascade cleanup anymore). Not re-run locally in this session (submodules/deps not initialized here).

Supersedes #191.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WER1oSuN8tCQTNRU73Mi89

Same texts as PR #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
Copilot AI lite review requested due to automatic review settings September 16, 2026 20:16
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

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.

🟢 Approval recommended

No unresolved review comments; migration insert and rollback logic are complete.

Pull request overview

Adds a TypeORM migration for seminar duplicate-lesson IVR texts using a real timestamp.

Changes:

  • Seeds two texts for user_id 0.
  • Removes both texts on rollback.
  • Uses chronological timestamp 1789587905258.
File summaries
File Description
server/src/migrations/1789587905258-UpdateYemotTextsSeminarDuplicateLesson.ts Seeds and removes duplicate-lesson texts.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

@buzz-code buzz-code changed the title Add seminar duplicate-lesson texts migration with real timestamp Seminar duplicate-lesson guard (from PR #191, real migration timestamp) Sep 16, 2026
Strip the ReportGroup/ReportGroupSession cascade cleanup on "delete
previous": it never checked Grade rows also FK-referencing
ReportGroupSession (ON DELETE NO ACTION), so it could throw and abort
the whole transaction. Orphaned group/session rows are harmless, so
just stop touching them and only delete the duplicate AttReport rows.

Also move the duplicate check right after the lesson is resolved
(before the roster fetch), so the caller is asked as soon as
possible, while the actual delete now happens atomically inside
saveSeminarAttendance's transaction, right before the fresh rows are
inserted.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WER1oSuN8tCQTNRU73Mi89
@buzz-code
buzz-code merged commit bf72274 into main Sep 17, 2026
4 checks passed
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.

3 participants