From ba35938e4ced0511452dab6b433f7a608ac253de Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Sep 2026 08:05:07 +0000 Subject: [PATCH 1/3] Group teacher-attendance-reported cards by class, fix reported-hour timezone - teacher_reported_today view now also exposes klassReferenceId - Client groups report cards into one column per class - Report date/hour now always render in Israel time (Asia/Jerusalem) instead of the viewer's browser timezone --- .../src/entities/teacher-reported-today.jsx | 106 ++++++++++++------ .../TeacherReportedToday.entity.ts | 4 + ...0000-AddKlassToTeacherReportedTodayView.ts | 22 ++++ 3 files changed, 97 insertions(+), 35 deletions(-) create mode 100644 server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index f2581f40..1b69e2c4 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -16,8 +16,11 @@ const filterDefaultValues = { 'reportDate:$lte': todayDateOnly, }; -const formatDate = (value) => (value ? new Date(value).toLocaleDateString('he-IL') : ''); -const formatHour = (value) => (value ? new Date(value).toLocaleTimeString('he-IL', { hour: '2-digit', minute: '2-digit' }) : ''); +const ISRAEL_TIMEZONE = 'Asia/Jerusalem'; +const formatDate = (value) => (value ? new Date(value).toLocaleDateString('he-IL', { timeZone: ISRAEL_TIMEZONE }) : ''); +const formatHour = (value) => (value ? new Date(value).toLocaleTimeString('he-IL', { hour: '2-digit', minute: '2-digit', timeZone: ISRAEL_TIMEZONE }) : ''); + +const NO_KLASS_KEY = 'none'; // The view has one row per teacher+lesson+date; group rows sharing the same // teacher+date into a single card, collecting their lesson rows. @@ -35,44 +38,77 @@ function groupByTeacherAndDate(rows) { return [...groups.values()]; } +// Split teacher cards into one column per class, so reports are easy to scan by class. +function groupByKlass(groups) { + const columns = new Map(); + groups.forEach((group) => { + const key = group.klassReferenceId ?? NO_KLASS_KEY; + if (!columns.has(key)) { + columns.set(key, { klassReferenceId: group.klassReferenceId, groups: [] }); + } + columns.get(key).groups.push(group); + }); + return [...columns.values()].sort((a, b) => { + if (!a.klassReferenceId) return 1; + if (!b.klassReferenceId) return -1; + return a.klassReferenceId - b.klassReferenceId; + }); +} + const TeacherReportCards = ({ isAdmin }) => { const { data } = useListContext(); const groups = groupByTeacherAndDate(data || []); + const columns = groupByKlass(groups); return ( - - {groups.map((group) => ( - - - - - - - - - - - {isAdmin && } - {formatDate(group.reportDate)} - {formatHour(group.reportHour)} - - - - {group.lessonRows.length > 0 ? ( - group.lessonRows.map((row) => ( - - - - - - )) - ) : ( - ללא שיוך שיעור - )} - - - - + + {columns.map((column) => ( + + + {column.klassReferenceId ? ( + + + + + + ) : 'ללא כיתה'} + + + {column.groups.map((group) => ( + + + + + + + + + + + {isAdmin && } + {formatDate(group.reportDate)} + {formatHour(group.reportHour)} + + + + {group.lessonRows.length > 0 ? ( + group.lessonRows.map((row) => ( + + + + + + )) + ) : ( + ללא שיוך שיעור + )} + + + + + ))} + + ))} ); diff --git a/server/src/db/view-entities/TeacherReportedToday.entity.ts b/server/src/db/view-entities/TeacherReportedToday.entity.ts index 31a0b515..7a13a193 100644 --- a/server/src/db/view-entities/TeacherReportedToday.entity.ts +++ b/server/src/db/view-entities/TeacherReportedToday.entity.ts @@ -14,6 +14,7 @@ import { AttReport } from '../entities/AttReport.entity'; .addSelect('att_report.reportDate', 'reportDate') .addSelect('att_report.teacherReferenceId', 'teacherReferenceId') .addSelect('att_report.lessonReferenceId', 'lessonReferenceId') + .addSelect('MIN(att_report.klassReferenceId)', 'klassReferenceId') .addSelect( 'MIN(MIN(att_report.createdAt)) OVER (PARTITION BY att_report.userId, att_report.teacherReferenceId, att_report.reportDate)', 'reportHour', @@ -41,6 +42,9 @@ export class TeacherReportedToday implements IHasUserId { @Column({ nullable: true }) lessonReferenceId: number; + @Column({ nullable: true }) + klassReferenceId: number; + @Column() reportHour: Date; } diff --git a/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts b/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts new file mode 100644 index 00000000..1be612b9 --- /dev/null +++ b/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddKlassToTeacherReportedTodayView1787600000000 implements MigrationInterface { + name = 'AddKlassToTeacherReportedTodayView1787600000000' + + 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\`, MIN(\`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')) AS \`id\`, MIN(MIN(\`att_report\`.\`created_at\`)) OVER (PARTITION BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`) AS \`reportHour\` 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\``); + 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`, MIN(`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')) AS `id`, MIN(MIN(`att_report`.`created_at`)) OVER (PARTITION BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`) AS `reportHour` 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`"]); + } + + 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\`.\`report_date\` AS \`reportDate\`, CONCAT(\`att_report\`.\`user_id\`, '_', \`att_report\`.\`teacherReferenceId\`, '_', \`att_report\`.\`report_date\`, '_', COALESCE(\`att_report\`.\`lessonReferenceId\`, 'null')) AS \`id\`, MIN(MIN(\`att_report\`.\`created_at\`)) OVER (PARTITION BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`) AS \`reportHour\` 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\``); + 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`.`report_date` AS `reportDate`, CONCAT(`att_report`.`user_id`, '_', `att_report`.`teacherReferenceId`, '_', `att_report`.`report_date`, '_', COALESCE(`att_report`.`lessonReferenceId`, 'null')) AS `id`, MIN(MIN(`att_report`.`created_at`)) OVER (PARTITION BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`) AS `reportHour` 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`"]); + } + +} From c3c5cebc0295d59be9e8abff00478135faf872cf Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Sep 2026 08:55:25 +0000 Subject: [PATCH 2/3] Address review: keep klass a real group-by key, fix Israel-tz default filter - teacher_reported_today view groups by klassReferenceId (not MIN()) and includes it in the row id, so rows for different classes on the same teacher/lesson/date no longer collapse or collide on id - Client card grouping key includes klassReferenceId so cards from different classes never merge into one card / wrong column - Default "today" date filter now uses Asia/Jerusalem instead of UTC, matching the display formatting --- client/src/entities/teacher-reported-today.jsx | 6 +++--- server/src/db/view-entities/TeacherReportedToday.entity.ts | 7 ++++--- .../1787600000000-AddKlassToTeacherReportedTodayView.ts | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index 1b69e2c4..bf8e7006 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -3,7 +3,8 @@ import { Box, Card, CardContent, Typography } from '@mui/material'; import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; -const todayDateOnly = new Date().toISOString().slice(0, 10); +const ISRAEL_TIMEZONE = 'Asia/Jerusalem'; +const todayDateOnly = new Date().toLocaleDateString('en-CA', { timeZone: ISRAEL_TIMEZONE }); const filters = [ adminUserFilter, @@ -16,7 +17,6 @@ const filterDefaultValues = { 'reportDate:$lte': todayDateOnly, }; -const ISRAEL_TIMEZONE = 'Asia/Jerusalem'; const formatDate = (value) => (value ? new Date(value).toLocaleDateString('he-IL', { timeZone: ISRAEL_TIMEZONE }) : ''); const formatHour = (value) => (value ? new Date(value).toLocaleTimeString('he-IL', { hour: '2-digit', minute: '2-digit', timeZone: ISRAEL_TIMEZONE }) : ''); @@ -27,7 +27,7 @@ const NO_KLASS_KEY = 'none'; function groupByTeacherAndDate(rows) { const groups = new Map(); rows.forEach((row) => { - const key = `${row.userId}_${row.teacherReferenceId}_${row.reportDate}`; + const key = `${row.userId}_${row.teacherReferenceId}_${row.reportDate}_${row.klassReferenceId ?? NO_KLASS_KEY}`; if (!groups.has(key)) { groups.set(key, { ...row, lessonRows: [] }); } diff --git a/server/src/db/view-entities/TeacherReportedToday.entity.ts b/server/src/db/view-entities/TeacherReportedToday.entity.ts index 7a13a193..f26a1e3f 100644 --- a/server/src/db/view-entities/TeacherReportedToday.entity.ts +++ b/server/src/db/view-entities/TeacherReportedToday.entity.ts @@ -7,14 +7,14 @@ import { AttReport } from '../entities/AttReport.entity'; dataSource .createQueryBuilder() .select( - "CONCAT(att_report.userId, '_', att_report.teacherReferenceId, '_', att_report.reportDate, '_', COALESCE(att_report.lessonReferenceId, 'null'))", + "CONCAT(att_report.userId, '_', att_report.teacherReferenceId, '_', att_report.reportDate, '_', COALESCE(att_report.lessonReferenceId, 'null'), '_', COALESCE(att_report.klassReferenceId, 'null'))", 'id', ) .addSelect('att_report.userId', 'userId') .addSelect('att_report.reportDate', 'reportDate') .addSelect('att_report.teacherReferenceId', 'teacherReferenceId') .addSelect('att_report.lessonReferenceId', 'lessonReferenceId') - .addSelect('MIN(att_report.klassReferenceId)', 'klassReferenceId') + .addSelect('att_report.klassReferenceId', 'klassReferenceId') .addSelect( 'MIN(MIN(att_report.createdAt)) OVER (PARTITION BY att_report.userId, att_report.teacherReferenceId, att_report.reportDate)', 'reportHour', @@ -24,7 +24,8 @@ import { AttReport } from '../entities/AttReport.entity'; .groupBy('att_report.userId') .addGroupBy('att_report.teacherReferenceId') .addGroupBy('att_report.reportDate') - .addGroupBy('att_report.lessonReferenceId'), + .addGroupBy('att_report.lessonReferenceId') + .addGroupBy('att_report.klassReferenceId'), }) export class TeacherReportedToday implements IHasUserId { @Column() diff --git a/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts b/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts index 1be612b9..81c0e0dd 100644 --- a/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts +++ b/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts @@ -7,8 +7,8 @@ export class AddKlassToTeacherReportedTodayView1787600000000 implements Migratio 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\`, MIN(\`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')) AS \`id\`, MIN(MIN(\`att_report\`.\`created_at\`)) OVER (PARTITION BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`) AS \`reportHour\` 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\``); - 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`, MIN(`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')) AS `id`, MIN(MIN(`att_report`.`created_at`)) OVER (PARTITION BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`) AS `reportHour` 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`"]); + 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\`) AS \`reportHour\` 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`) AS `reportHour` 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 5d171edc99de5e975a2a90b0b516423dcb13f3f5 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Sep 2026 09:05:33 +0000 Subject: [PATCH 3/3] Address review: scope reportHour window to class, fix stale comment - reportHour window now partitions by klassReferenceId too, so a class's card shows that class's own earliest report time instead of possibly the earliest across all of the teacher's classes that day - Updated groupByTeacherAndDate comment to reflect klass is now part of the grouping key --- client/src/entities/teacher-reported-today.jsx | 4 ++-- server/src/db/view-entities/TeacherReportedToday.entity.ts | 2 +- .../1787600000000-AddKlassToTeacherReportedTodayView.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index bf8e7006..ba418c45 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -22,8 +22,8 @@ const formatHour = (value) => (value ? new Date(value).toLocaleTimeString('he-IL const NO_KLASS_KEY = 'none'; -// The view has one row per teacher+lesson+date; group rows sharing the same -// teacher+date into a single card, collecting their lesson rows. +// 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. function groupByTeacherAndDate(rows) { const groups = new Map(); rows.forEach((row) => { diff --git a/server/src/db/view-entities/TeacherReportedToday.entity.ts b/server/src/db/view-entities/TeacherReportedToday.entity.ts index f26a1e3f..dc596f8d 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)', + 'MIN(MIN(att_report.createdAt)) OVER (PARTITION BY att_report.userId, att_report.teacherReferenceId, att_report.reportDate, att_report.klassReferenceId)', 'reportHour', ) .from(AttReport, 'att_report') diff --git a/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts b/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts index 81c0e0dd..5d315aee 100644 --- a/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts +++ b/server/src/migrations/1787600000000-AddKlassToTeacherReportedTodayView.ts @@ -7,8 +7,8 @@ export class AddKlassToTeacherReportedTodayView1787600000000 implements Migratio 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\`) AS \`reportHour\` 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`) AS `reportHour` 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\`.\`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\` 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` 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 {