From cc0b0d88bd0dde0f2f83a764d94c21c6c60f7588 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 16:38:36 +0000 Subject: [PATCH 1/7] Fix missing girls total concatenating string counts in teacher reported today summary Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld --- client/src/entities/teacher-reported-today.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index 19c7bebb..20f07639 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -66,8 +66,8 @@ function groupByKlass(groups) { // count when it has no per-lesson breakdown (the "ללא שיוך שיעור" case). function getTotalMissingGirls(group) { return group.lessonRows.length > 0 - ? group.lessonRows.reduce((sum, row) => sum + (row.missingGirlsCount || 0), 0) - : group.missingGirlsCount || 0; + ? group.lessonRows.reduce((sum, row) => sum + (Number(row.missingGirlsCount) || 0), 0) + : Number(group.missingGirlsCount) || 0; } const TeacherReportCards = ({ isAdmin }) => { From 9123ce796e051c17aad29e240679de53e981b6ed Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 16:41:39 +0000 Subject: [PATCH 2/7] Show separate card per lesson in teacher reported today view Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld --- client/src/entities/teacher-reported-today.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index 20f07639..78f80e07 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -29,12 +29,12 @@ const formatHour = (value) => (value ? new Date(value).toLocaleTimeString('he-IL const NO_KLASS_KEY = 'none'; -// The view has one row per teacher+lesson+date+klass; group rows sharing the same -// teacher+date+klass into a single card, collecting their lesson rows. +// The view has one row per teacher+lesson+date+klass; each lesson gets its own card, +// so a teacher who taught two lessons shows as two cards. function groupByTeacherAndDate(rows) { const groups = new Map(); rows.forEach((row) => { - const key = `${row.userId}_${row.teacherReferenceId}_${row.reportDate}_${row.klassReferenceId ?? NO_KLASS_KEY}`; + const key = `${row.userId}_${row.teacherReferenceId}_${row.reportDate}_${row.klassReferenceId ?? NO_KLASS_KEY}_${row.lessonReferenceId ?? 'none'}`; if (!groups.has(key)) { groups.set(key, { ...row, lessonRows: [] }); } From c8dad6e357c50718d6c1922e0234517c6eb6c4d4 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 16:43:47 +0000 Subject: [PATCH 3/7] Show each lesson's own report hour in teacher reported today view Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld --- .../TeacherReportedToday.entity.ts | 2 +- ...HourPerLessonInTeacherReportedTodayView.ts | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 server/src/migrations/1791305020926-ReportHourPerLessonInTeacherReportedTodayView.ts diff --git a/server/src/db/view-entities/TeacherReportedToday.entity.ts b/server/src/db/view-entities/TeacherReportedToday.entity.ts index 5f0fc2c1..0881d836 100644 --- a/server/src/db/view-entities/TeacherReportedToday.entity.ts +++ b/server/src/db/view-entities/TeacherReportedToday.entity.ts @@ -16,7 +16,7 @@ import { AttReport } from '../entities/AttReport.entity'; .addSelect('att_report.lessonReferenceId', 'lessonReferenceId') .addSelect('att_report.klassReferenceId', 'klassReferenceId') .addSelect( - 'MIN(MIN(att_report.createdAt)) OVER (PARTITION BY att_report.userId, att_report.teacherReferenceId, att_report.reportDate, att_report.klassReferenceId)', + 'MIN(att_report.createdAt)', 'reportHour', ) .addSelect( diff --git a/server/src/migrations/1791305020926-ReportHourPerLessonInTeacherReportedTodayView.ts b/server/src/migrations/1791305020926-ReportHourPerLessonInTeacherReportedTodayView.ts new file mode 100644 index 00000000..586459dd --- /dev/null +++ b/server/src/migrations/1791305020926-ReportHourPerLessonInTeacherReportedTodayView.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class ReportHourPerLessonInTeacherReportedTodayView1791305020926 implements MigrationInterface { + name = 'ReportHourPerLessonInTeacherReportedTodayView1791305020926' + + public async up(queryRunner: QueryRunner): Promise { + const dbName = queryRunner.connection.options.database; + await queryRunner.query(`DELETE FROM \`${dbName}\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","teacher_reported_today",dbName]); + await queryRunner.query(`DROP VIEW IF EXISTS \`teacher_reported_today\``); + await queryRunner.query(`CREATE OR REPLACE VIEW \`teacher_reported_today\` AS SELECT \`att_report\`.\`user_id\` AS \`userId\`, \`att_report\`.\`teacherReferenceId\` AS \`teacherReferenceId\`, \`att_report\`.\`lessonReferenceId\` AS \`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\` AS \`klassReferenceId\`, \`att_report\`.\`report_date\` AS \`reportDate\`, CONCAT(\`att_report\`.\`user_id\`, '_', \`att_report\`.\`teacherReferenceId\`, '_', \`att_report\`.\`report_date\`, '_', COALESCE(\`att_report\`.\`lessonReferenceId\`, 'null'), '_', COALESCE(\`att_report\`.\`klassReferenceId\`, 'null')) AS \`id\`, MIN(\`att_report\`.\`created_at\`) AS \`reportHour\`, COUNT(DISTINCT CASE WHEN \`att_report\`.\`abs_count\` > 0 THEN \`att_report\`.\`studentReferenceId\` END) AS \`missingGirlsCount\` FROM \`att_reports\` \`att_report\` WHERE \`att_report\`.\`teacherReferenceId\` IS NOT NULL GROUP BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`, \`att_report\`.\`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\``); + await queryRunner.query(`INSERT INTO \`${dbName}\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, [dbName,"VIEW","teacher_reported_today","SELECT `att_report`.`user_id` AS `userId`, `att_report`.`teacherReferenceId` AS `teacherReferenceId`, `att_report`.`lessonReferenceId` AS `lessonReferenceId`, `att_report`.`klassReferenceId` AS `klassReferenceId`, `att_report`.`report_date` AS `reportDate`, CONCAT(`att_report`.`user_id`, '_', `att_report`.`teacherReferenceId`, '_', `att_report`.`report_date`, '_', COALESCE(`att_report`.`lessonReferenceId`, 'null'), '_', COALESCE(`att_report`.`klassReferenceId`, 'null')) AS `id`, MIN(`att_report`.`created_at`) AS `reportHour`, COUNT(DISTINCT CASE WHEN `att_report`.`abs_count` > 0 THEN `att_report`.`studentReferenceId` END) AS `missingGirlsCount` FROM `att_reports` `att_report` WHERE `att_report`.`teacherReferenceId` IS NOT NULL GROUP BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`, `att_report`.`lessonReferenceId`, `att_report`.`klassReferenceId`"]); + } + + public async down(queryRunner: QueryRunner): Promise { + const dbName = queryRunner.connection.options.database; + await queryRunner.query(`DELETE FROM \`${dbName}\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","teacher_reported_today",dbName]); + await queryRunner.query(`DROP VIEW IF EXISTS \`teacher_reported_today\``); + await queryRunner.query(`CREATE OR REPLACE VIEW \`teacher_reported_today\` AS SELECT \`att_report\`.\`user_id\` AS \`userId\`, \`att_report\`.\`teacherReferenceId\` AS \`teacherReferenceId\`, \`att_report\`.\`lessonReferenceId\` AS \`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\` AS \`klassReferenceId\`, \`att_report\`.\`report_date\` AS \`reportDate\`, CONCAT(\`att_report\`.\`user_id\`, '_', \`att_report\`.\`teacherReferenceId\`, '_', \`att_report\`.\`report_date\`, '_', COALESCE(\`att_report\`.\`lessonReferenceId\`, 'null'), '_', COALESCE(\`att_report\`.\`klassReferenceId\`, 'null')) AS \`id\`, MIN(MIN(\`att_report\`.\`created_at\`)) OVER (PARTITION BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`, \`att_report\`.\`klassReferenceId\`) AS \`reportHour\`, COUNT(DISTINCT CASE WHEN \`att_report\`.\`abs_count\` > 0 THEN \`att_report\`.\`studentReferenceId\` END) AS \`missingGirlsCount\` FROM \`att_reports\` \`att_report\` WHERE \`att_report\`.\`teacherReferenceId\` IS NOT NULL GROUP BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`, \`att_report\`.\`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\``); + await queryRunner.query(`INSERT INTO \`${dbName}\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, [dbName,"VIEW","teacher_reported_today","SELECT `att_report`.`user_id` AS `userId`, `att_report`.`teacherReferenceId` AS `teacherReferenceId`, `att_report`.`lessonReferenceId` AS `lessonReferenceId`, `att_report`.`klassReferenceId` AS `klassReferenceId`, `att_report`.`report_date` AS `reportDate`, CONCAT(`att_report`.`user_id`, '_', `att_report`.`teacherReferenceId`, '_', `att_report`.`report_date`, '_', COALESCE(`att_report`.`lessonReferenceId`, 'null'), '_', COALESCE(`att_report`.`klassReferenceId`, 'null')) AS `id`, MIN(MIN(`att_report`.`created_at`)) OVER (PARTITION BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`, `att_report`.`klassReferenceId`) AS `reportHour`, COUNT(DISTINCT CASE WHEN `att_report`.`abs_count` > 0 THEN `att_report`.`studentReferenceId` END) AS `missingGirlsCount` FROM `att_reports` `att_report` WHERE `att_report`.`teacherReferenceId` IS NOT NULL GROUP BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`, `att_report`.`lessonReferenceId`, `att_report`.`klassReferenceId`"]); + } + +} From cf7981f98c77fcfb874c92278de21d171d4300d5 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 17:01:30 +0000 Subject: [PATCH 4/7] Hide zero missing-girls badge in teacher reported today view Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld --- client/src/entities/teacher-reported-today.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index 78f80e07..a8750b2c 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -116,7 +116,7 @@ const TeacherReportCards = ({ isAdmin }) => { {group.lessonRows.length > 0 ? ( group.lessonRows.map((row) => ( - + From 3bfe77beb5a2ee39ec4bb656264fbb09d4e8ac22 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 17:07:25 +0000 Subject: [PATCH 5/7] Match teacher_reported_today migration SQL to TypeORM generated view Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld --- ...305020926-ReportHourPerLessonInTeacherReportedTodayView.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/migrations/1791305020926-ReportHourPerLessonInTeacherReportedTodayView.ts b/server/src/migrations/1791305020926-ReportHourPerLessonInTeacherReportedTodayView.ts index 586459dd..98a12032 100644 --- a/server/src/migrations/1791305020926-ReportHourPerLessonInTeacherReportedTodayView.ts +++ b/server/src/migrations/1791305020926-ReportHourPerLessonInTeacherReportedTodayView.ts @@ -7,8 +7,8 @@ export class ReportHourPerLessonInTeacherReportedTodayView1791305020926 implemen const dbName = queryRunner.connection.options.database; await queryRunner.query(`DELETE FROM \`${dbName}\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","teacher_reported_today",dbName]); await queryRunner.query(`DROP VIEW IF EXISTS \`teacher_reported_today\``); - await queryRunner.query(`CREATE OR REPLACE VIEW \`teacher_reported_today\` AS SELECT \`att_report\`.\`user_id\` AS \`userId\`, \`att_report\`.\`teacherReferenceId\` AS \`teacherReferenceId\`, \`att_report\`.\`lessonReferenceId\` AS \`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\` AS \`klassReferenceId\`, \`att_report\`.\`report_date\` AS \`reportDate\`, CONCAT(\`att_report\`.\`user_id\`, '_', \`att_report\`.\`teacherReferenceId\`, '_', \`att_report\`.\`report_date\`, '_', COALESCE(\`att_report\`.\`lessonReferenceId\`, 'null'), '_', COALESCE(\`att_report\`.\`klassReferenceId\`, 'null')) AS \`id\`, MIN(\`att_report\`.\`created_at\`) AS \`reportHour\`, COUNT(DISTINCT CASE WHEN \`att_report\`.\`abs_count\` > 0 THEN \`att_report\`.\`studentReferenceId\` END) AS \`missingGirlsCount\` FROM \`att_reports\` \`att_report\` WHERE \`att_report\`.\`teacherReferenceId\` IS NOT NULL GROUP BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`, \`att_report\`.\`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\``); - await queryRunner.query(`INSERT INTO \`${dbName}\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, [dbName,"VIEW","teacher_reported_today","SELECT `att_report`.`user_id` AS `userId`, `att_report`.`teacherReferenceId` AS `teacherReferenceId`, `att_report`.`lessonReferenceId` AS `lessonReferenceId`, `att_report`.`klassReferenceId` AS `klassReferenceId`, `att_report`.`report_date` AS `reportDate`, CONCAT(`att_report`.`user_id`, '_', `att_report`.`teacherReferenceId`, '_', `att_report`.`report_date`, '_', COALESCE(`att_report`.`lessonReferenceId`, 'null'), '_', COALESCE(`att_report`.`klassReferenceId`, 'null')) AS `id`, MIN(`att_report`.`created_at`) AS `reportHour`, COUNT(DISTINCT CASE WHEN `att_report`.`abs_count` > 0 THEN `att_report`.`studentReferenceId` END) AS `missingGirlsCount` FROM `att_reports` `att_report` WHERE `att_report`.`teacherReferenceId` IS NOT NULL GROUP BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`, `att_report`.`lessonReferenceId`, `att_report`.`klassReferenceId`"]); + await queryRunner.query(`CREATE OR REPLACE VIEW \`teacher_reported_today\` AS SELECT \`att_report\`.\`user_id\` AS \`userId\`, \`att_report\`.\`teacherReferenceId\` AS \`teacherReferenceId\`, \`att_report\`.\`klassReferenceId\` AS \`klassReferenceId\`, \`att_report\`.\`lessonReferenceId\` AS \`lessonReferenceId\`, \`att_report\`.\`report_date\` AS \`reportDate\`, CONCAT(\`att_report\`.\`user_id\`, '_', \`att_report\`.\`teacherReferenceId\`, '_', \`att_report\`.\`report_date\`, '_', COALESCE(\`att_report\`.\`lessonReferenceId\`, 'null'), '_', COALESCE(\`att_report\`.\`klassReferenceId\`, 'null')) AS \`id\`, MIN(\`att_report\`.\`created_at\`) AS \`reportHour\`, COUNT(DISTINCT CASE WHEN \`att_report\`.\`abs_count\` > 0 THEN \`att_report\`.\`studentReferenceId\` END) AS \`missingGirlsCount\` FROM \`att_reports\` \`att_report\` WHERE \`att_report\`.\`teacherReferenceId\` IS NOT NULL GROUP BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`, \`att_report\`.\`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\``); + await queryRunner.query(`INSERT INTO \`${dbName}\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, [dbName,"VIEW","teacher_reported_today","SELECT `att_report`.`user_id` AS `userId`, `att_report`.`teacherReferenceId` AS `teacherReferenceId`, `att_report`.`klassReferenceId` AS `klassReferenceId`, `att_report`.`lessonReferenceId` AS `lessonReferenceId`, `att_report`.`report_date` AS `reportDate`, CONCAT(`att_report`.`user_id`, '_', `att_report`.`teacherReferenceId`, '_', `att_report`.`report_date`, '_', COALESCE(`att_report`.`lessonReferenceId`, 'null'), '_', COALESCE(`att_report`.`klassReferenceId`, 'null')) AS `id`, MIN(`att_report`.`created_at`) AS `reportHour`, COUNT(DISTINCT CASE WHEN `att_report`.`abs_count` > 0 THEN `att_report`.`studentReferenceId` END) AS `missingGirlsCount` FROM `att_reports` `att_report` WHERE `att_report`.`teacherReferenceId` IS NOT NULL GROUP BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`, `att_report`.`lessonReferenceId`, `att_report`.`klassReferenceId`"]); } public async down(queryRunner: QueryRunner): Promise { From c0bb5bbfd148509fd961abd7c4645335ed31a23d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 17:07:25 +0000 Subject: [PATCH 6/7] Always create report group session for seminar phone reports Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld --- server/src/yemot-handler.service.test.ts | 20 +++++++------ server/src/yemot-handler.service.ts | 36 +++++++++++------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/server/src/yemot-handler.service.test.ts b/server/src/yemot-handler.service.test.ts index 053e9836..9f5daa66 100644 --- a/server/src/yemot-handler.service.test.ts +++ b/server/src/yemot-handler.service.test.ts @@ -418,7 +418,7 @@ describe('YemotHandlerService — react-admin-nestjs', () => { } }); - it('happy path without lessonSignature permission — saves AttReport rows without a report group', async () => { + it('happy path without lessonSignature permission — still creates a ReportGroup/Session', async () => { jest.setSystemTime(israelTimeAt(7, 0)); const year = getCurrentHebrewYear(); const klass = { id: 210, userId: 1, key: 8, name: 'Klass Eight', year }; @@ -438,10 +438,11 @@ describe('YemotHandlerService — react-admin-nestjs', () => { expect(result.hungup).toBe(true); expect(result.saved['AttReport']).toHaveLength(3); - expect(result.saved['ReportGroup']).toHaveLength(0); - expect(result.saved['ReportGroupSession']).toHaveLength(0); + expect(result.saved['ReportGroup']).toHaveLength(1); + expect(result.saved['ReportGroupSession']).toHaveLength(1); + const session = result.saved['ReportGroupSession'][0]; for (const report of result.saved['AttReport']) { - expect(report.reportGroupSessionId).toBeFalsy(); + expect(report.reportGroupSessionId).toBe(session.id); } }); @@ -732,18 +733,21 @@ describe('YemotHandlerService — react-admin-nestjs', () => { expect(reports).toHaveLength(4); const freshRows = reports.filter((r: any) => r.lessonReferenceId === 700); expect(freshRows.map((r: any) => r.studentReferenceId).sort()).toEqual([101, 102, 103]); + const freshSessionId = freshRows[0].reportGroupSessionId; for (const report of freshRows) { expect(report.absCount).toBe(0); - expect(report.reportGroupSessionId).toBeFalsy(); + expect(report.reportGroupSessionId).toBe(freshSessionId); } expect(reports.some((r: any) => r.id === 913)).toBe(true); - // Report groups/sessions are left untouched — deleting a duplicate report only + // Prior report groups/sessions are left untouched — deleting a duplicate report only // removes AttReport rows, it never cascades into ReportGroup/ReportGroupSession. + // The fresh report adds its own group/session. const sessions = await repo('ReportGroupSession').find(); - expect(sessions.map((s: any) => s.id).sort()).toEqual([900, 901, 902]); + expect(sessions.map((s: any) => s.id).sort()).toEqual([900, 901, 902, freshSessionId]); const groups = await repo('ReportGroup').find(); - expect(groups.map((g: any) => g.id).sort()).toEqual([800, 801]); + expect(groups).toHaveLength(3); + expect(groups.map((g: any) => g.id)).toEqual(expect.arrayContaining([800, 801])); } finally { await ds.destroy(); } diff --git a/server/src/yemot-handler.service.ts b/server/src/yemot-handler.service.ts index 4e1dcb9f..cf02da6e 100644 --- a/server/src/yemot-handler.service.ts +++ b/server/src/yemot-handler.service.ts @@ -311,27 +311,23 @@ export class YemotHandlerService extends BaseYemotHandlerService { }); } - let reportGroupSessionId: number | undefined; - - if (hasPermission(this.user, 'lessonSignature')) { - const reportGroup = await manager.getRepository(ReportGroup).save({ - userId: this.user.id, - name: `נוכחות סמינר - ${klass.name}`, - topic: 'נוכחות סמינר', - teacherReferenceId: teacher.id, - klassReferenceId: klass.id, - year: getCurrentHebrewYear(), - }); - - const reportGroupSession = await manager.getRepository(ReportGroupSession).save({ - userId: this.user.id, - reportGroupId: reportGroup.id, - sessionDate: reportDate, - startTime: callTime, - }); + // Always create a session, so each phone report is its own lesson (teacher_reported_today relies on it). + const reportGroup = await manager.getRepository(ReportGroup).save({ + userId: this.user.id, + name: `נוכחות סמינר - ${klass.name}`, + topic: 'נוכחות סמינר', + teacherReferenceId: teacher.id, + klassReferenceId: klass.id, + year: getCurrentHebrewYear(), + }); - reportGroupSessionId = reportGroupSession.id; - } + const reportGroupSession = await manager.getRepository(ReportGroupSession).save({ + userId: this.user.id, + reportGroupId: reportGroup.id, + sessionDate: reportDate, + startTime: callTime, + }); + const reportGroupSessionId = reportGroupSession.id; const rows = roster.map((studentKlass) => attReportRepo.create({ From 5dc157836d281323d387d313a836e85c9b163b8c Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 17:08:59 +0000 Subject: [PATCH 7/7] Revert "Always create report group session for seminar phone reports" Keep session creation gated by lessonSignature. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Po2GocBhFneXD2k9z1f6Ld --- server/src/yemot-handler.service.test.ts | 20 ++++++------- server/src/yemot-handler.service.ts | 36 +++++++++++++----------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/server/src/yemot-handler.service.test.ts b/server/src/yemot-handler.service.test.ts index 9f5daa66..053e9836 100644 --- a/server/src/yemot-handler.service.test.ts +++ b/server/src/yemot-handler.service.test.ts @@ -418,7 +418,7 @@ describe('YemotHandlerService — react-admin-nestjs', () => { } }); - it('happy path without lessonSignature permission — still creates a ReportGroup/Session', async () => { + it('happy path without lessonSignature permission — saves AttReport rows without a report group', async () => { jest.setSystemTime(israelTimeAt(7, 0)); const year = getCurrentHebrewYear(); const klass = { id: 210, userId: 1, key: 8, name: 'Klass Eight', year }; @@ -438,11 +438,10 @@ describe('YemotHandlerService — react-admin-nestjs', () => { expect(result.hungup).toBe(true); expect(result.saved['AttReport']).toHaveLength(3); - expect(result.saved['ReportGroup']).toHaveLength(1); - expect(result.saved['ReportGroupSession']).toHaveLength(1); - const session = result.saved['ReportGroupSession'][0]; + expect(result.saved['ReportGroup']).toHaveLength(0); + expect(result.saved['ReportGroupSession']).toHaveLength(0); for (const report of result.saved['AttReport']) { - expect(report.reportGroupSessionId).toBe(session.id); + expect(report.reportGroupSessionId).toBeFalsy(); } }); @@ -733,21 +732,18 @@ describe('YemotHandlerService — react-admin-nestjs', () => { expect(reports).toHaveLength(4); const freshRows = reports.filter((r: any) => r.lessonReferenceId === 700); expect(freshRows.map((r: any) => r.studentReferenceId).sort()).toEqual([101, 102, 103]); - const freshSessionId = freshRows[0].reportGroupSessionId; for (const report of freshRows) { expect(report.absCount).toBe(0); - expect(report.reportGroupSessionId).toBe(freshSessionId); + expect(report.reportGroupSessionId).toBeFalsy(); } expect(reports.some((r: any) => r.id === 913)).toBe(true); - // Prior report groups/sessions are left untouched — deleting a duplicate report only + // Report groups/sessions are left untouched — deleting a duplicate report only // removes AttReport rows, it never cascades into ReportGroup/ReportGroupSession. - // The fresh report adds its own group/session. const sessions = await repo('ReportGroupSession').find(); - expect(sessions.map((s: any) => s.id).sort()).toEqual([900, 901, 902, freshSessionId]); + expect(sessions.map((s: any) => s.id).sort()).toEqual([900, 901, 902]); const groups = await repo('ReportGroup').find(); - expect(groups).toHaveLength(3); - expect(groups.map((g: any) => g.id)).toEqual(expect.arrayContaining([800, 801])); + expect(groups.map((g: any) => g.id).sort()).toEqual([800, 801]); } finally { await ds.destroy(); } diff --git a/server/src/yemot-handler.service.ts b/server/src/yemot-handler.service.ts index cf02da6e..4e1dcb9f 100644 --- a/server/src/yemot-handler.service.ts +++ b/server/src/yemot-handler.service.ts @@ -311,23 +311,27 @@ export class YemotHandlerService extends BaseYemotHandlerService { }); } - // Always create a session, so each phone report is its own lesson (teacher_reported_today relies on it). - const reportGroup = await manager.getRepository(ReportGroup).save({ - userId: this.user.id, - name: `נוכחות סמינר - ${klass.name}`, - topic: 'נוכחות סמינר', - teacherReferenceId: teacher.id, - klassReferenceId: klass.id, - year: getCurrentHebrewYear(), - }); + let reportGroupSessionId: number | undefined; - const reportGroupSession = await manager.getRepository(ReportGroupSession).save({ - userId: this.user.id, - reportGroupId: reportGroup.id, - sessionDate: reportDate, - startTime: callTime, - }); - const reportGroupSessionId = reportGroupSession.id; + if (hasPermission(this.user, 'lessonSignature')) { + const reportGroup = await manager.getRepository(ReportGroup).save({ + userId: this.user.id, + name: `נוכחות סמינר - ${klass.name}`, + topic: 'נוכחות סמינר', + teacherReferenceId: teacher.id, + klassReferenceId: klass.id, + year: getCurrentHebrewYear(), + }); + + const reportGroupSession = await manager.getRepository(ReportGroupSession).save({ + userId: this.user.id, + reportGroupId: reportGroup.id, + sessionDate: reportDate, + startTime: callTime, + }); + + reportGroupSessionId = reportGroupSession.id; + } const rows = roster.map((studentKlass) => attReportRepo.create({