From 79fc0cb73ec961e28708a7b918e106832e7b51c3 Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Sun, 4 Jan 2026 18:40:56 +0000 Subject: [PATCH 01/12] refactor: add TeacherGuard to InLessonReport routes and export TeacherGuard component --- client/src/App.jsx | 14 +++++++++++--- client/src/RootDashboard.jsx | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/src/App.jsx b/client/src/App.jsx index 59d38419..0bb7ea36 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -18,7 +18,7 @@ const appTheme = createTheme({ }); import { Layout } from 'src/GeneralLayout'; -import { RootDashboard } from 'src/RootDashboard'; +import { RootDashboard, TeacherGuard } from 'src/RootDashboard'; import { resourceEntityGuesser } from '@shared/components/crudContainers/EntityGuesser'; import attReport from "src/entities/att-report"; @@ -131,8 +131,16 @@ const App = () => ( - } /> - } /> + + + + } /> + + + + } /> ); diff --git a/client/src/RootDashboard.jsx b/client/src/RootDashboard.jsx index e366cb9b..c7ecb598 100644 --- a/client/src/RootDashboard.jsx +++ b/client/src/RootDashboard.jsx @@ -20,7 +20,7 @@ export const RootDashboard = (props) => { } } -const TeacherGuard = ({ children }) => { +export const TeacherGuard = ({ children }) => { const dataProvider = useDataProvider(); const notify = useNotify(); const { value: teacher, set: setTeacher, clear } = useObjectStore('teacher'); From 0b505feafa4721d9f5df87d7b3dd529e8bfafba2 Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Sun, 4 Jan 2026 19:16:31 +0000 Subject: [PATCH 02/12] refactor: enhance TeacherGuard layout and improve user experience --- client/src/RootDashboard.jsx | 81 ++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 13 deletions(-) diff --git a/client/src/RootDashboard.jsx b/client/src/RootDashboard.jsx index c7ecb598..55f75d66 100644 --- a/client/src/RootDashboard.jsx +++ b/client/src/RootDashboard.jsx @@ -4,6 +4,14 @@ import { useObjectStore } from 'src/utils/storeUtil'; import { Dashboard } from 'src/GeneralLayout'; import { useIsTeacherView } from 'src/utils/appPermissions'; import Button from '@mui/material/Button'; +import Card from '@mui/material/Card'; +import CardContent from '@mui/material/CardContent'; +import Box from '@mui/material/Box'; +import Typography from '@mui/material/Typography'; +import Avatar from '@mui/material/Avatar'; +import LockOutlinedIcon from '@mui/icons-material/LockOutlined'; +import LogoutIcon from '@mui/icons-material/Logout'; +import Paper from '@mui/material/Paper'; export const RootDashboard = (props) => { const isTeacherView = useIsTeacherView(); @@ -26,13 +34,35 @@ export const TeacherGuard = ({ children }) => { const { value: teacher, set: setTeacher, clear } = useObjectStore('teacher'); if (teacher) { - return
- שלום המורה {teacher.name} - - {children} -
+ return ( + + + + שלום המורה {teacher.name} + + + + + {children} + + + ); } const handleSubmit = async (values) => { @@ -52,11 +82,36 @@ export const TeacherGuard = ({ children }) => { }; return ( - - - }> - - + + + + + + + + כניסת מורה + + + + + + } + > + + + + + ); } From 5f6b3519649e637ee13d3e25fadc48d0bf2215b2 Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 08:18:06 +0000 Subject: [PATCH 03/12] refactor: optimize value saving logic in AutoPersistInStore component --- .../src/reports/in-lesson-report/AutoPersistInStore.jsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/src/reports/in-lesson-report/AutoPersistInStore.jsx b/client/src/reports/in-lesson-report/AutoPersistInStore.jsx index 3c49062f..665caf34 100644 --- a/client/src/reports/in-lesson-report/AutoPersistInStore.jsx +++ b/client/src/reports/in-lesson-report/AutoPersistInStore.jsx @@ -1,7 +1,7 @@ import { useEffect } from 'react'; import { useFormContext } from 'react-hook-form'; import { useStore } from 'react-admin'; -import { debounce } from 'lodash'; +import { debounce, isEqual } from 'lodash'; export const AutoPersistInStore = ({ storeKey }) => { const { watch, reset, getValues } = useFormContext(); @@ -25,13 +25,15 @@ export const AutoPersistInStore = ({ storeKey }) => { // Debounce to avoid too many writes useEffect(() => { const save = debounce((val) => { - setSavedValue(val); + if (!isEqual(val, savedValue)) { + setSavedValue(val); + } }, 1000); save(values); return () => save.cancel(); - }, [values, setSavedValue]); + }, [values, setSavedValue, savedValue]); return null; }; From 4a59cf000eeb53d71298b547b57d40006caa3a6f Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 16:35:12 +0000 Subject: [PATCH 04/12] refactor: remove AutoPersistInStore component and update import path in MainReport --- client/shared | 2 +- .../in-lesson-report/AutoPersistInStore.jsx | 39 ------------------- .../reports/in-lesson-report/MainReport.jsx | 2 +- 3 files changed, 2 insertions(+), 41 deletions(-) delete mode 100644 client/src/reports/in-lesson-report/AutoPersistInStore.jsx diff --git a/client/shared b/client/shared index af82e20e..a87f227a 160000 --- a/client/shared +++ b/client/shared @@ -1 +1 @@ -Subproject commit af82e20e8d9859d3c7d9257737dc7b7fd75093cb +Subproject commit a87f227adc90205c4e79437b9485f5c77f5a29ee diff --git a/client/src/reports/in-lesson-report/AutoPersistInStore.jsx b/client/src/reports/in-lesson-report/AutoPersistInStore.jsx deleted file mode 100644 index 665caf34..00000000 --- a/client/src/reports/in-lesson-report/AutoPersistInStore.jsx +++ /dev/null @@ -1,39 +0,0 @@ -import { useEffect } from 'react'; -import { useFormContext } from 'react-hook-form'; -import { useStore } from 'react-admin'; -import { debounce, isEqual } from 'lodash'; - -export const AutoPersistInStore = ({ storeKey }) => { - const { watch, reset, getValues } = useFormContext(); - const [savedValue, setSavedValue] = useStore(storeKey); - - // Restore saved value on mount - useEffect(() => { - if (savedValue) { - // We merge with current values to avoid overwriting default values if savedValue is partial - // But for a full form restore, reset(savedValue) is usually what we want. - // However, we must be careful if the form schema changed. - reset(savedValue); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - - // Watch all fields - const values = watch(); - - // Save values to store on change - // Debounce to avoid too many writes - useEffect(() => { - const save = debounce((val) => { - if (!isEqual(val, savedValue)) { - setSavedValue(val); - } - }, 1000); - - save(values); - - return () => save.cancel(); - }, [values, setSavedValue, savedValue]); - - return null; -}; diff --git a/client/src/reports/in-lesson-report/MainReport.jsx b/client/src/reports/in-lesson-report/MainReport.jsx index 60676b2d..a47fcce9 100644 --- a/client/src/reports/in-lesson-report/MainReport.jsx +++ b/client/src/reports/in-lesson-report/MainReport.jsx @@ -5,7 +5,7 @@ import { ReportHeader } from './ReportHeader'; import { getDefaultReportDate, StudentList } from './StudentList'; import LessonSignatureFields from '../../components/LessonSignatureFields'; import { FormActions } from './FormActions'; -import { AutoPersistInStore } from './AutoPersistInStore'; +import { AutoPersistInStore } from '@shared/components/form/AutoPersistInStore'; export const MainReport = ({ gradeMode, handleSave, storePrefix }) => { const [reportDates, setReportDates] = useStore(`${storePrefix}.reportDates`, [getDefaultReportDate()]); From 4f04f8f279110a8700ebdf1bb73cb9c0fa24c50c Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 16:39:51 +0000 Subject: [PATCH 05/12] refactor: enhance TeacherGuard layout and improve logout functionality --- client/src/components/TeacherAccess.jsx | 84 ++++++++++++++++++++----- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/client/src/components/TeacherAccess.jsx b/client/src/components/TeacherAccess.jsx index 2f690ce1..325935ce 100644 --- a/client/src/components/TeacherAccess.jsx +++ b/client/src/components/TeacherAccess.jsx @@ -1,6 +1,15 @@ +import React from 'react'; import { useDataProvider, SimpleForm, TextInput, useNotify, Toolbar, SaveButton } from 'react-admin'; import { useObjectStore } from 'src/utils/storeUtil'; import Button from '@mui/material/Button'; +import Card from '@mui/material/Card'; +import CardContent from '@mui/material/CardContent'; +import Box from '@mui/material/Box'; +import Typography from '@mui/material/Typography'; +import Avatar from '@mui/material/Avatar'; +import LockOutlinedIcon from '@mui/icons-material/LockOutlined'; +import LogoutIcon from '@mui/icons-material/Logout'; +import Paper from '@mui/material/Paper'; export const TeacherGuard = ({ children }) => { const dataProvider = useDataProvider(); @@ -8,13 +17,35 @@ export const TeacherGuard = ({ children }) => { const { value: teacher, set: setTeacher, clear } = useObjectStore('teacher'); if (teacher) { - return
- שלום המורה {teacher.name} - - {children} -
+ return ( + + + + שלום המורה {teacher.name} + + + + + {children} + + + ); } const handleSubmit = async (values) => { @@ -34,11 +65,36 @@ export const TeacherGuard = ({ children }) => { }; return ( - - - }> - - + + + + + + + + כניסת מורה + + + + + + } + > + + + + + ); -} \ No newline at end of file +} From 18268b18b295103d1f8122ec54072fcd8f3acfa3 Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 17:06:30 +0000 Subject: [PATCH 06/12] refactor: replace userId filters with adminUserFilter and commonAdminFilters across multiple entities --- client/src/entities/att-grade-effect.jsx | 4 ++-- client/src/entities/att-report-with-report-month.jsx | 8 ++------ client/src/entities/att-report.jsx | 8 ++------ client/src/entities/attendance-name.jsx | 3 ++- client/src/entities/grade-name.jsx | 4 ++-- client/src/entities/grade.jsx | 7 ++----- client/src/entities/klass-type.jsx | 3 ++- client/src/entities/klass.jsx | 7 ++----- client/src/entities/known-absence.jsx | 7 ++----- client/src/entities/lesson.jsx | 7 ++----- client/src/entities/report-month.jsx | 8 ++------ client/src/entities/student-klass.jsx | 7 ++----- client/src/entities/student-klasses-report.jsx | 3 ++- client/src/entities/student-percent-report.jsx | 3 ++- client/src/entities/student.jsx | 7 ++----- client/src/entities/teacher-grade-report-status.jsx | 3 ++- client/src/entities/teacher-report-status.jsx | 3 ++- client/src/entities/teacher-salary-report.jsx | 3 ++- client/src/entities/teacher.jsx | 8 ++------ client/src/pivots/PercentReportWithDatesList.jsx | 3 ++- client/src/pivots/StudentAttendanceList.jsx | 3 ++- 21 files changed, 42 insertions(+), 67 deletions(-) diff --git a/client/src/entities/att-grade-effect.jsx b/client/src/entities/att-grade-effect.jsx index ac77cf80..3d5f7ba2 100644 --- a/client/src/entities/att-grade-effect.jsx +++ b/client/src/entities/att-grade-effect.jsx @@ -2,10 +2,10 @@ import { NumberInput, TextField, TextInput, ReferenceField, DateField, DateTimeI import { CommonDatagrid } from '@shared/components/crudContainers/CommonList'; import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; -import { CommonReferenceInputFilter } from '@shared/components/fields/CommonReferenceInputFilter'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , , diff --git a/client/src/entities/att-report-with-report-month.jsx b/client/src/entities/att-report-with-report-month.jsx index 9412d8e4..87d452f0 100644 --- a/client/src/entities/att-report-with-report-month.jsx +++ b/client/src/entities/att-report-with-report-month.jsx @@ -12,14 +12,10 @@ import { Inputs } from './att-report'; import { CommonHebrewDateField } from '@shared/components/fields/CommonHebrewDateField'; import { BulkActionButton } from '@shared/components/crudContainers/BulkActionButton'; import { BulkFixReferenceButton } from '@shared/components/crudContainers/BulkFixReferenceButton'; -import { useIsLessonSignature } from 'src/utils/appPermissions'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , , diff --git a/client/src/entities/att-report.jsx b/client/src/entities/att-report.jsx index 30019c58..3a6ebb6d 100644 --- a/client/src/entities/att-report.jsx +++ b/client/src/entities/att-report.jsx @@ -7,14 +7,10 @@ import { CommonReferenceInputFilter, filterByUserId, filterByUserIdAndYear } fro import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; -import { CommonHebrewDateField } from '@shared/components/fields/CommonHebrewDateField'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , , diff --git a/client/src/entities/attendance-name.jsx b/client/src/entities/attendance-name.jsx index 417950c1..7bc2782f 100644 --- a/client/src/entities/attendance-name.jsx +++ b/client/src/entities/attendance-name.jsx @@ -4,9 +4,10 @@ import { CommonRepresentation } from '@shared/components/CommonRepresentation'; import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; import { CommonReferenceInputFilter } from '@shared/components/fields/CommonReferenceInputFilter'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , ]; diff --git a/client/src/entities/grade-name.jsx b/client/src/entities/grade-name.jsx index 417950c1..bf3212c4 100644 --- a/client/src/entities/grade-name.jsx +++ b/client/src/entities/grade-name.jsx @@ -3,10 +3,10 @@ import { CommonDatagrid } from '@shared/components/crudContainers/CommonList'; import { CommonRepresentation } from '@shared/components/CommonRepresentation'; import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; -import { CommonReferenceInputFilter } from '@shared/components/fields/CommonReferenceInputFilter'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , ]; diff --git a/client/src/entities/grade.jsx b/client/src/entities/grade.jsx index 628c79a8..f3edf0de 100644 --- a/client/src/entities/grade.jsx +++ b/client/src/entities/grade.jsx @@ -6,13 +6,10 @@ import { CommonReferenceInputFilter, filterByUserId, filterByUserIdAndYear } fro import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , , diff --git a/client/src/entities/klass-type.jsx b/client/src/entities/klass-type.jsx index 2101bf66..bff05af2 100644 --- a/client/src/entities/klass-type.jsx +++ b/client/src/entities/klass-type.jsx @@ -6,9 +6,10 @@ import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; import { MultiReferenceField } from '@shared/components/fields/CommonReferenceField'; import { filterByUserId, CommonReferenceInputFilter } from '@shared/components/fields/CommonReferenceInputFilter'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , ]; diff --git a/client/src/entities/klass.jsx b/client/src/entities/klass.jsx index 278d58b6..465d9f57 100644 --- a/client/src/entities/klass.jsx +++ b/client/src/entities/klass.jsx @@ -11,13 +11,10 @@ import { useUnique } from '@shared/utils/useUnique'; import { BulkReportButton } from '@shared/components/crudContainers/BulkReportButton'; import CommonReferenceArrayInput from '@shared/components/fields/CommonReferenceArrayInput'; import AssignmentIcon from '@mui/icons-material/Assignment'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , , diff --git a/client/src/entities/known-absence.jsx b/client/src/entities/known-absence.jsx index 06b36ea4..c1be5d44 100644 --- a/client/src/entities/known-absence.jsx +++ b/client/src/entities/known-absence.jsx @@ -8,13 +8,10 @@ import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; import { CommonHebrewDateField } from '@shared/components/fields/CommonHebrewDateField'; import { BulkApproveAbsences } from 'src/components/BulkApproveAbsences'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , , diff --git a/client/src/entities/lesson.jsx b/client/src/entities/lesson.jsx index f4d72db6..c6878b1a 100644 --- a/client/src/entities/lesson.jsx +++ b/client/src/entities/lesson.jsx @@ -9,13 +9,10 @@ import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; import CommonReferenceArrayInput from '@shared/components/fields/CommonReferenceArrayInput'; import { useUnique } from '@shared/utils/useUnique'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , , diff --git a/client/src/entities/report-month.jsx b/client/src/entities/report-month.jsx index 607f75c2..70cef157 100644 --- a/client/src/entities/report-month.jsx +++ b/client/src/entities/report-month.jsx @@ -4,15 +4,11 @@ import { CommonRepresentation } from '@shared/components/CommonRepresentation'; import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; -import { CommonReferenceInputFilter } from '@shared/components/fields/CommonReferenceInputFilter'; import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , , diff --git a/client/src/entities/student-klass.jsx b/client/src/entities/student-klass.jsx index fbd76be1..709ec66d 100644 --- a/client/src/entities/student-klass.jsx +++ b/client/src/entities/student-klass.jsx @@ -8,13 +8,10 @@ import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; import StudentReportCardReactButton from 'src/reports/studentReportCardReactButton'; import { BulkFixReferenceButton } from '@shared/components/crudContainers/BulkFixReferenceButton'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , , diff --git a/client/src/entities/student-klasses-report.jsx b/client/src/entities/student-klasses-report.jsx index 9b16a3ba..5a92543c 100644 --- a/client/src/entities/student-klasses-report.jsx +++ b/client/src/entities/student-klasses-report.jsx @@ -6,9 +6,10 @@ import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; import StudentReportCardReactButton from 'src/reports/studentReportCardReactButton'; import { CommonReferenceInputFilter, filterByUserId, filterByUserIdAndYear } from '@shared/components/fields/CommonReferenceInputFilter'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , , diff --git a/client/src/entities/student-percent-report.jsx b/client/src/entities/student-percent-report.jsx index bdc186e4..d6dc62cf 100644 --- a/client/src/entities/student-percent-report.jsx +++ b/client/src/entities/student-percent-report.jsx @@ -6,9 +6,10 @@ import { CommonReferenceInputFilter, filterByUserId, filterByUserIdAndYear } fro import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import { ShowMatchingRecordsButton } from '@shared/components/fields/ShowMatchingRecordsButton'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, // , // , , diff --git a/client/src/entities/student.jsx b/client/src/entities/student.jsx index c09a74ad..a93fa407 100644 --- a/client/src/entities/student.jsx +++ b/client/src/entities/student.jsx @@ -10,13 +10,10 @@ import { CommonReferenceInputFilter } from '@shared/components/fields/CommonRefe import StudentReportCardReactButton from 'src/reports/studentReportCardReactButton'; import { BulkActionButton } from '@shared/components/crudContainers/BulkActionButton'; import CheckCircleIcon from '@mui/icons-material/CheckCircle'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , ,, diff --git a/client/src/entities/teacher-grade-report-status.jsx b/client/src/entities/teacher-grade-report-status.jsx index e6ca3412..2f92b35d 100644 --- a/client/src/entities/teacher-grade-report-status.jsx +++ b/client/src/entities/teacher-grade-report-status.jsx @@ -9,9 +9,10 @@ import BrowserUpdatedIcon from '@mui/icons-material/BrowserUpdated'; import { CommonRichTextInput } from '@shared/components/fields/CommonRichTextInput'; import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , , diff --git a/client/src/entities/teacher-report-status.jsx b/client/src/entities/teacher-report-status.jsx index 2f13aead..bc4f1b17 100644 --- a/client/src/entities/teacher-report-status.jsx +++ b/client/src/entities/teacher-report-status.jsx @@ -9,9 +9,10 @@ import BrowserUpdatedIcon from '@mui/icons-material/BrowserUpdated'; import { CommonRichTextInput } from '@shared/components/fields/CommonRichTextInput'; import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , , diff --git a/client/src/entities/teacher-salary-report.jsx b/client/src/entities/teacher-salary-report.jsx index 1a6b8dc4..bbeeb63f 100644 --- a/client/src/entities/teacher-salary-report.jsx +++ b/client/src/entities/teacher-salary-report.jsx @@ -5,9 +5,10 @@ import { CommonReferenceInputFilter, filterByUserId } from '@shared/components/f import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; import { MultiReferenceField } from '@shared/components/fields/CommonReferenceField'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , , diff --git a/client/src/entities/teacher.jsx b/client/src/entities/teacher.jsx index 62e8c0ab..58b14039 100644 --- a/client/src/entities/teacher.jsx +++ b/client/src/entities/teacher.jsx @@ -4,14 +4,10 @@ import { CommonRepresentation } from '@shared/components/CommonRepresentation'; import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; import { useUnique } from '@shared/utils/useUnique'; -import { CommonReferenceInputFilter } from '@shared/components/fields/CommonReferenceInputFilter'; +import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , - ({ isAdmin }) => isAdmin && , + ...commonAdminFilters, , , ]; diff --git a/client/src/pivots/PercentReportWithDatesList.jsx b/client/src/pivots/PercentReportWithDatesList.jsx index 2c395dfc..896fb2d6 100644 --- a/client/src/pivots/PercentReportWithDatesList.jsx +++ b/client/src/pivots/PercentReportWithDatesList.jsx @@ -6,9 +6,10 @@ import { CommonReferenceInputFilter, filterByUserId, filterByUserIdAndYear } fro import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import { ShowMatchingRecordsButton } from '@shared/components/fields/ShowMatchingRecordsButton'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; +import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , , diff --git a/client/src/pivots/StudentAttendanceList.jsx b/client/src/pivots/StudentAttendanceList.jsx index 07b18ff1..a646add0 100644 --- a/client/src/pivots/StudentAttendanceList.jsx +++ b/client/src/pivots/StudentAttendanceList.jsx @@ -7,9 +7,10 @@ import CommonAutocompleteInput from '@shared/components/fields/CommonAutocomplet import { CommonSelectArrayField } from "@shared/components/fields/CommonSelectArrayField"; import { semesterChoices } from "src/entities/report-month"; import CommonReferenceArrayInput from "@shared/components/fields/CommonReferenceArrayInput"; +import { adminUserFilter } from "@shared/components/fields/PermissionFilter"; const filters = [ - ({ isAdmin }) => isAdmin && , + adminUserFilter, , , , From 4a4bb9929c7714a64f807139e820987417eac5d4 Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 20:45:43 +0000 Subject: [PATCH 07/12] refactor: add CommonHebrewDateField import to att-report component --- client/src/entities/att-report.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/entities/att-report.jsx b/client/src/entities/att-report.jsx index 3a6ebb6d..c3ed3d0b 100644 --- a/client/src/entities/att-report.jsx +++ b/client/src/entities/att-report.jsx @@ -8,6 +8,7 @@ import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; +import { CommonHebrewDateField } from '@shared/components/fields/CommonHebrewDateField'; const filters = [ ...commonAdminFilters, From bf3c3ffb1cdd25fbdbf7b3ba8c9dd25de217e951 Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 20:54:37 +0000 Subject: [PATCH 08/12] refactor: update import_file schema by adding new fields and renaming filename to fileName --- db/data.sql | 13 ++-- .../1767646406606-FixImportFileSchema.ts | 78 +++++++++++++++++++ 2 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 server/src/migrations/1767646406606-FixImportFileSchema.ts diff --git a/db/data.sql b/db/data.sql index fe95609a..57070fbf 100644 --- a/db/data.sql +++ b/db/data.sql @@ -141,7 +141,8 @@ INSERT INTO `migrations` (`timestamp`, `name`) VALUES (1762283756079, 'regenerateReportGroupSessions1762283756079'), (1763834256494, 'optimizeLessonKlassNameView1763834256494'), (1763931783912, 'OptimizeLessonKlassJoin1763931783912'), -(1763933862682, 'OptimizeLessonKlassJsonTable1763933862682'); +(1763933862682, 'OptimizeLessonKlassJsonTable1763933862682'), +(1767646406606, 'FixImportFileSchema1767646406606'); -- ============================================================ -- Table: users @@ -912,12 +913,14 @@ DROP TABLE IF EXISTS `import_file`; CREATE TABLE `import_file` ( `id` int NOT NULL AUTO_INCREMENT, `userId` int NOT NULL, - `filename` varchar(255) NOT NULL, + `fileName` varchar(255) NOT NULL, + `fileSource` varchar(255) NOT NULL, + `entityIds` text NOT NULL, `entityName` varchar(255) NOT NULL, - `status` varchar(50) DEFAULT 'pending', - `isReverted` tinyint(1) NOT NULL DEFAULT '0', + `fullSuccess` tinyint(1) DEFAULT NULL, + `response` varchar(255) DEFAULT NULL, + `metadata` json DEFAULT NULL, `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/server/src/migrations/1767646406606-FixImportFileSchema.ts b/server/src/migrations/1767646406606-FixImportFileSchema.ts new file mode 100644 index 00000000..1315a0a2 --- /dev/null +++ b/server/src/migrations/1767646406606-FixImportFileSchema.ts @@ -0,0 +1,78 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class FixImportFileSchema1767646406606 implements MigrationInterface { + name = 'FixImportFileSchema1767646406606' + + public async up(queryRunner: QueryRunner): Promise { + // Check and add fileSource + const hasFileSource = await queryRunner.hasColumn('import_file', 'fileSource'); + if (!hasFileSource) { + await queryRunner.query(`ALTER TABLE \`import_file\` ADD \`fileSource\` varchar(255) NOT NULL`); + } + + // Check and add entityIds + const hasEntityIds = await queryRunner.hasColumn('import_file', 'entityIds'); + if (!hasEntityIds) { + await queryRunner.query(`ALTER TABLE \`import_file\` ADD \`entityIds\` text NOT NULL`); + } + + // Check and add fullSuccess + const hasFullSuccess = await queryRunner.hasColumn('import_file', 'fullSuccess'); + if (!hasFullSuccess) { + await queryRunner.query(`ALTER TABLE \`import_file\` ADD \`fullSuccess\` tinyint(1) DEFAULT NULL`); + } + + // Check and add response + const hasResponse = await queryRunner.hasColumn('import_file', 'response'); + if (!hasResponse) { + await queryRunner.query(`ALTER TABLE \`import_file\` ADD \`response\` varchar(255) DEFAULT NULL`); + } + + // Check and add metadata + const hasMetadata = await queryRunner.hasColumn('import_file', 'metadata'); + if (!hasMetadata) { + await queryRunner.query(`ALTER TABLE \`import_file\` ADD \`metadata\` json DEFAULT NULL`); + } + + // Check and drop status + const hasStatus = await queryRunner.hasColumn('import_file', 'status'); + if (hasStatus) { + await queryRunner.query(`ALTER TABLE \`import_file\` DROP COLUMN \`status\``); + } + + // Check and drop isReverted + const hasIsReverted = await queryRunner.hasColumn('import_file', 'isReverted'); + if (hasIsReverted) { + await queryRunner.query(`ALTER TABLE \`import_file\` DROP COLUMN \`isReverted\``); + } + + // Check and drop updatedAt + const hasUpdatedAt = await queryRunner.hasColumn('import_file', 'updatedAt'); + if (hasUpdatedAt) { + await queryRunner.query(`ALTER TABLE \`import_file\` DROP COLUMN \`updatedAt\``); + } + + // Check and rename filename to fileName + // Note: hasColumn is case sensitive usually depending on DB collation, but here we check specifically. + // If 'filename' exists and 'fileName' does not (or we just want to rename), we check. + // However, in some MySQL setups on Windows/Mac, case might be ignored. + // But the error showed `Unknown column 'fileSource'`, and the `data.sql` had `filename`. + // The entity has `fileName`. + // Let's check if we can rename. + const hasFilenameLower = await queryRunner.hasColumn('import_file', 'filename'); + const hasFileNameCamel = await queryRunner.hasColumn('import_file', 'fileName'); + + // If we have 'filename' but not 'fileName' (or if they are considered different), rename. + // If the DB is case-insensitive, hasFilenameLower might return true for 'fileName' too. + // To be safe, we can try to change it if it's not exactly what we want, but 'CHANGE' requires knowing the old name. + // If case insensitive, `CHANGE filename fileName` might just change the casing. + if (hasFilenameLower) { + // We just run it, if it's already fileName it might just update metadata or do nothing. + await queryRunner.query(`ALTER TABLE \`import_file\` CHANGE \`filename\` \`fileName\` varchar(255) NOT NULL`); + } + } + + public async down(queryRunner: QueryRunner): Promise { + // No-op for safety as this is a fix-up migration + } +} From ffa61e2512c0b17f3fa4dd363d6bc6e604e2204f Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 21:01:43 +0000 Subject: [PATCH 09/12] update shared client --- client/shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/shared b/client/shared index a87f227a..d3a984fd 160000 --- a/client/shared +++ b/client/shared @@ -1 +1 @@ -Subproject commit a87f227adc90205c4e79437b9485f5c77f5a29ee +Subproject commit d3a984fd09894d724d2e38f5e544342936fb8920 From 93a3522de74b8e5b911a95ad07e593671cfe3db2 Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 21:07:10 +0000 Subject: [PATCH 10/12] refactor: fix and optimize att_report_with_report_month view by adding reportMonthReferenceId --- db/data.sql | 13 +++++----- .../1767647010979-FixAttReportView.ts | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 server/src/migrations/1767647010979-FixAttReportView.ts diff --git a/db/data.sql b/db/data.sql index 57070fbf..298b7beb 100644 --- a/db/data.sql +++ b/db/data.sql @@ -142,7 +142,8 @@ INSERT INTO `migrations` (`timestamp`, `name`) VALUES (1763834256494, 'optimizeLessonKlassNameView1763834256494'), (1763931783912, 'OptimizeLessonKlassJoin1763931783912'), (1763933862682, 'OptimizeLessonKlassJsonTable1763933862682'), -(1767646406606, 'FixImportFileSchema1767646406606'); +(1767646406606, 'FixImportFileSchema1767646406606'), +(1767647010979, 'FixAttReportView1767647010979'); -- ============================================================ -- Table: users @@ -1085,12 +1086,12 @@ FROM texts; -- View: att_report_with_report_month CREATE OR REPLACE VIEW `att_report_with_report_month` AS SELECT - ar.*, - rm.id AS reportMonthId, - rm.name AS reportMonthName + rm.id AS reportMonthReferenceId, + ar.* FROM att_reports ar -LEFT JOIN report_month rm ON ar.report_date BETWEEN rm.startDate AND rm.endDate - AND ar.user_id = rm.userId AND ar.year = rm.year; +LEFT JOIN report_month rm ON ar.user_id = rm.userId + AND ar.report_date <= rm.endDate + AND ar.report_date >= rm.startDate; -- View: grade_with_report_month CREATE OR REPLACE VIEW `grade_with_report_month` AS diff --git a/server/src/migrations/1767647010979-FixAttReportView.ts b/server/src/migrations/1767647010979-FixAttReportView.ts new file mode 100644 index 00000000..0eb1c684 --- /dev/null +++ b/server/src/migrations/1767647010979-FixAttReportView.ts @@ -0,0 +1,26 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class FixAttReportView1767647010979 implements MigrationInterface { + name = 'FixAttReportView1767647010979' + + public async up(queryRunner: QueryRunner): Promise { + const hasColumn = await queryRunner.hasColumn('att_report_with_report_month', 'reportMonthReferenceId'); + if (!hasColumn) { + await queryRunner.query(` + CREATE OR REPLACE VIEW \`att_report_with_report_month\` AS + SELECT \`report_months\`.\`id\` AS \`reportMonthReferenceId\`, + ar.* + FROM \`att_reports\` \`ar\` + LEFT JOIN \`report_month\` \`report_months\` ON \`ar\`.\`user_id\` = \`report_months\`.\`userId\` + AND \`ar\`.\`report_date\` <= \`report_months\`.\`endDate\` + AND \`ar\`.\`report_date\` >= \`report_months\`.\`startDate\` + `); + } + } + + public async down(queryRunner: QueryRunner): Promise { + // Revert to previous state if needed, but usually we just want the fix. + // This is a best-effort revert to what might have been there or just drop. + // For now, we can leave it or restore the old broken view if strictness is required. + } +} From eb6120cfd685d5a9620787c289a0ab3c3d649808 Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 21:07:17 +0000 Subject: [PATCH 11/12] refactor: add useIsLessonSignature import to att-report-with-report-month component --- client/src/entities/att-report-with-report-month.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/entities/att-report-with-report-month.jsx b/client/src/entities/att-report-with-report-month.jsx index 87d452f0..f5779f0c 100644 --- a/client/src/entities/att-report-with-report-month.jsx +++ b/client/src/entities/att-report-with-report-month.jsx @@ -13,6 +13,7 @@ import { CommonHebrewDateField } from '@shared/components/fields/CommonHebrewDat import { BulkActionButton } from '@shared/components/crudContainers/BulkActionButton'; import { BulkFixReferenceButton } from '@shared/components/crudContainers/BulkFixReferenceButton'; import { commonAdminFilters } from '@shared/components/fields/PermissionFilter'; +import { useIsLessonSignature } from 'src/utils/appPermissions'; const filters = [ ...commonAdminFilters, From 9602863c938e4311225b1382cdf69911261da0e2 Mon Sep 17 00:00:00 2001 From: Hadasa Schechter <72219643+buzz-code@users.noreply.github.com> Date: Mon, 5 Jan 2026 21:17:30 +0000 Subject: [PATCH 12/12] refactor: fix report month dates and remove overlaps in migration script --- db/data.sql | 135 +++++++++--------- .../1767647702833-FixDataDatesAndOverlaps.ts | 74 ++++++++++ 2 files changed, 141 insertions(+), 68 deletions(-) create mode 100644 server/src/migrations/1767647702833-FixDataDatesAndOverlaps.ts diff --git a/db/data.sql b/db/data.sql index 298b7beb..6bbde991 100644 --- a/db/data.sql +++ b/db/data.sql @@ -143,7 +143,8 @@ INSERT INTO `migrations` (`timestamp`, `name`) VALUES (1763931783912, 'OptimizeLessonKlassJoin1763931783912'), (1763933862682, 'OptimizeLessonKlassJsonTable1763933862682'), (1767646406606, 'FixImportFileSchema1767646406606'), -(1767647010979, 'FixAttReportView1767647010979'); +(1767647010979, 'FixAttReportView1767647010979'), +(1767647702833, 'FixDataDatesAndOverlaps1767647702833'); -- ============================================================ -- Table: users @@ -359,16 +360,16 @@ CREATE TABLE `lessons` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO `lessons` (`id`, `user_id`, `year`, `key`, `name`, `display_name`, `klasses`, `klassReferenceIds`, `teacher_id`, `teacherReferenceId`, `start_date`, `end_date`, `how_many_lessons`, `order`) VALUES -(1, 1, 5786, 1, 'Mathematics', 'Math', '1,2', '1,2', '123456789', 1, '5786-09-01', '5786-12-31', 40, 1), -(2, 1, 5786, 2, 'Hebrew', 'Hebrew', '1,2,3', '1,2,3', '234567890', 2, '5786-09-01', '5786-12-31', 45, 2), -(3, 1, 5786, 3, 'English', 'English', '3,4', '3,4', '345678901', 3, '5786-09-01', '5786-12-31', 38, 3), -(4, 1, 5786, 4, 'Science', 'Science', '5', '5', '456789012', 4, '5786-09-01', '5786-12-31', 42, 4), -(5, 1, 5786, 5, 'History', 'History', '4,5', '4,5', '567890123', 5, '5786-09-01', '5786-12-31', 35, 5), -(6, 2, 5786, 6, 'Geography', 'Geo', '6,7', '6,7', '678901234', 6, '5786-09-01', '5786-12-31', 30, 6), -(7, 2, 5786, 7, 'Computer Studies', 'CS', '10', '10', '789012345', 7, '5786-09-01', '5786-12-31', 48, 7), -(8, 1, 5786, 8, 'Literature', 'Lit', '9', '9', '890123456', 8, '5786-09-01', '5786-12-31', 36, 8), -(9, 1, 5786, 9, 'Physics', 'Physics', '8', '8', '901234567', 9, '5786-09-01', '5786-12-31', 44, 9), -(10, 3, 5786, 10, 'Chemistry', 'Chem', '8', '8', '012345678', 10, '5786-09-01', '5786-12-31', 41, 10); +(1, 1, 5786, 1, 'Mathematics', 'Math', '1,2', '1,2', '123456789', 1, '2025-09-01', '2025-12-31', 40, 1), +(2, 1, 5786, 2, 'Hebrew', 'Hebrew', '1,2,3', '1,2,3', '234567890', 2, '2025-09-01', '2025-12-31', 45, 2), +(3, 1, 5786, 3, 'English', 'English', '3,4', '3,4', '345678901', 3, '2025-09-01', '2025-12-31', 38, 3), +(4, 1, 5786, 4, 'Science', 'Science', '5', '5', '456789012', 4, '2025-09-01', '2025-12-31', 42, 4), +(5, 1, 5786, 5, 'History', 'History', '4,5', '4,5', '567890123', 5, '2025-09-01', '2025-12-31', 35, 5), +(6, 2, 5786, 6, 'Geography', 'Geo', '6,7', '6,7', '678901234', 6, '2025-09-01', '2025-12-31', 30, 6), +(7, 2, 5786, 7, 'Computer Studies', 'CS', '10', '10', '789012345', 7, '2025-09-01', '2025-12-31', 48, 7), +(8, 1, 5786, 8, 'Literature', 'Lit', '9', '9', '890123456', 8, '2025-09-01', '2025-12-31', 36, 8), +(9, 1, 5786, 9, 'Physics', 'Physics', '8', '8', '901234567', 9, '2025-09-01', '2025-12-31', 44, 9), +(10, 3, 5786, 10, 'Chemistry', 'Chem', '8', '8', '012345678', 10, '2025-09-01', '2025-12-31', 41, 10); -- ============================================================ -- Table: student_klasses @@ -453,21 +454,21 @@ CREATE TABLE `att_reports` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO `att_reports` (`id`, `user_id`, `year`, `student_tz`, `studentReferenceId`, `teacher_id`, `teacherReferenceId`, `klass_id`, `klassReferenceId`, `lesson_id`, `lessonReferenceId`, `report_date`, `how_many_lessons`, `abs_count`, `approved_abs_count`) VALUES -(1, 1, 5786, '111111111', 1, '123456789', 1, 1, 1, 1, 1, '5786-10-01', 2, 0, 0), -(2, 1, 5786, '222222222', 2, '123456789', 1, 1, 1, 1, 1, '5786-10-01', 2, 1, 0), -(3, 1, 5786, '333333333', 3, '234567890', 2, 2, 2, 2, 2, '5786-10-01', 2, 0, 0), -(4, 1, 5786, '444444444', 4, '234567890', 2, 2, 2, 2, 2, '5786-10-01', 2, 0.5, 0.5), -(5, 1, 5786, '555555555', 5, '345678901', 3, 3, 3, 3, 3, '5786-10-01', 2, 0, 0), -(6, 2, 5786, '666666666', 6, '456789012', 4, 4, 4, 4, 4, '5786-10-02', 2, 1.5, 1), -(7, 2, 5786, '777777777', 7, '567890123', 5, 5, 5, 5, 5, '5786-10-02', 2, 0, 0), -(8, 2, 5786, '888888888', 8, '678901234', 6, 6, 6, 6, 6, '5786-10-02', 1, 0, 0), -(9, 1, 5786, '999999999', 9, '789012345', 7, 7, 7, 7, 7, '5786-10-03', 2, 2, 0), -(10, 3, 5786, '101010101', 10, '890123456', 8, 8, 8, 8, 8, '5786-10-03', 2, 0, 0), -(11, 1, 5786, '111111111', 1, '234567890', 2, 1, 1, 2, 2, '5786-10-05', 2, 0, 0), -(12, 1, 5786, '333333333', 3, '345678901', 3, 2, 2, 3, 3, '5786-10-05', 2, 1, 1), -(13, 2, 5786, '666666666', 6, '456789012', 4, 4, 4, 5, 5, '5786-10-06', 2, 0, 0), -(14, 1, 5786, '555555555', 5, '567890123', 5, 3, 3, 5, 5, '5786-10-07', 2, 0.5, 0), -(15, 2, 5786, '888888888', 8, '789012345', 7, 7, 7, 7, 7, '5786-10-08', 2, 0, 0); +(1, 1, 5786, '111111111', 1, '123456789', 1, 1, 1, 1, 1, '2025-10-01', 2, 0, 0), +(2, 1, 5786, '222222222', 2, '123456789', 1, 1, 1, 1, 1, '2025-10-01', 2, 1, 0), +(3, 1, 5786, '333333333', 3, '234567890', 2, 2, 2, 2, 2, '2025-10-01', 2, 0, 0), +(4, 1, 5786, '444444444', 4, '234567890', 2, 2, 2, 2, 2, '2025-10-01', 2, 0.5, 0.5), +(5, 1, 5786, '555555555', 5, '345678901', 3, 3, 3, 3, 3, '2025-10-01', 2, 0, 0), +(6, 2, 5786, '666666666', 6, '456789012', 4, 4, 4, 4, 4, '2025-10-02', 2, 1.5, 1), +(7, 2, 5786, '777777777', 7, '567890123', 5, 5, 5, 5, 5, '2025-10-02', 2, 0, 0), +(8, 2, 5786, '888888888', 8, '678901234', 6, 6, 6, 6, 6, '2025-10-02', 1, 0, 0), +(9, 1, 5786, '999999999', 9, '789012345', 7, 7, 7, 7, 7, '2025-10-03', 2, 2, 0), +(10, 3, 5786, '101010101', 10, '890123456', 8, 8, 8, 8, 8, '2025-10-03', 2, 0, 0), +(11, 1, 5786, '111111111', 1, '234567890', 2, 1, 1, 2, 2, '2025-10-05', 2, 0, 0), +(12, 1, 5786, '333333333', 3, '345678901', 3, 2, 2, 3, 3, '2025-10-05', 2, 1, 1), +(13, 2, 5786, '666666666', 6, '456789012', 4, 4, 4, 5, 5, '2025-10-06', 2, 0, 0), +(14, 1, 5786, '555555555', 5, '567890123', 5, 3, 3, 5, 5, '2025-10-07', 2, 0.5, 0), +(15, 2, 5786, '888888888', 8, '789012345', 7, 7, 7, 7, 7, '2025-10-08', 2, 0, 0); -- ============================================================ -- Table: grades @@ -506,18 +507,18 @@ CREATE TABLE `grades` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO `grades` (`id`, `user_id`, `year`, `student_tz`, `studentReferenceId`, `teacher_id`, `teacherReferenceId`, `klass_id`, `klassReferenceId`, `lesson_id`, `lessonReferenceId`, `report_date`, `how_many_lessons`, `grade`, `estimation`) VALUES -(1, 1, 5786, '111111111', 1, '123456789', 1, 1, 1, 1, 1, '5786-10-15', 10, 95.5, 'Excellent'), -(2, 1, 5786, '222222222', 2, '123456789', 1, 1, 1, 1, 1, '5786-10-15', 10, 88.0, 'Very Good'), -(3, 1, 5786, '333333333', 3, '234567890', 2, 2, 2, 2, 2, '5786-10-15', 12, 92.5, 'Excellent'), -(4, 1, 5786, '444444444', 4, '234567890', 2, 2, 2, 2, 2, '5786-10-15', 12, 85.0, 'Good'), -(5, 1, 5786, '555555555', 5, '345678901', 3, 3, 3, 3, 3, '5786-10-15', 10, 90.0, 'Very Good'), -(6, 2, 5786, '666666666', 6, '456789012', 4, 4, 4, 4, 4, '5786-10-16', 11, 93.5, 'Excellent'), -(7, 2, 5786, '777777777', 7, '567890123', 5, 5, 5, 5, 5, '5786-10-16', 9, 87.5, 'Very Good'), -(8, 2, 5786, '888888888', 8, '678901234', 6, 6, 6, 6, 6, '5786-10-16', 8, 91.0, 'Excellent'), -(9, 1, 5786, '999999999', 9, '789012345', 7, 7, 7, 7, 7, '5786-10-17', 12, 78.5, 'Good'), -(10, 3, 5786, '101010101', 10, '890123456', 8, 8, 8, 8, 8, '5786-10-17', 10, 94.0, 'Excellent'), -(11, 1, 5786, '111111111', 1, '234567890', 2, 1, 1, 2, 2, '5786-10-20', 12, 89.5, 'Very Good'), -(12, 1, 5786, '333333333', 3, '345678901', 3, 2, 2, 3, 3, '5786-10-20', 10, 96.0, 'Outstanding'), +(1, 1, 5786, '111111111', 1, '123456789', 1, 1, 1, 1, 1, '2025-10-15', 10, 95.5, 'Excellent'), +(2, 1, 5786, '222222222', 2, '123456789', 1, 1, 1, 1, 1, '2025-10-15', 10, 88.0, 'Very Good'), +(3, 1, 5786, '333333333', 3, '234567890', 2, 2, 2, 2, 2, '2025-10-15', 12, 92.5, 'Excellent'), +(4, 1, 5786, '444444444', 4, '234567890', 2, 2, 2, 2, 2, '2025-10-15', 12, 85.0, 'Good'), +(5, 1, 5786, '555555555', 5, '345678901', 3, 3, 3, 3, 3, '2025-10-15', 10, 90.0, 'Very Good'), +(6, 2, 5786, '666666666', 6, '456789012', 4, 4, 4, 4, 4, '2025-10-16', 11, 93.5, 'Excellent'), +(7, 2, 5786, '777777777', 7, '567890123', 5, 5, 5, 5, 5, '2025-10-16', 9, 87.5, 'Very Good'), +(8, 2, 5786, '888888888', 8, '678901234', 6, 6, 6, 6, 6, '2025-10-16', 8, 91.0, 'Excellent'), +(9, 1, 5786, '999999999', 9, '789012345', 7, 7, 7, 7, 7, '2025-10-17', 12, 78.5, 'Good'), +(10, 3, 5786, '101010101', 10, '890123456', 8, 8, 8, 8, 8, '2025-10-17', 10, 94.0, 'Excellent'), +(11, 1, 5786, '111111111', 1, '234567890', 2, 1, 1, 2, 2, '2025-10-20', 12, 89.5, 'Very Good'), +(12, 1, 5786, '333333333', 3, '345678901', 3, 2, 2, 3, 3, '2025-10-20', 10, 96.0, 'Outstanding'), (13, 2, 5786, '666666666', 6, '567890123', 5, 4, 4, 5, 5, '5786-10-21', 9, 86.0, 'Good'), (14, 1, 5786, '555555555', 5, '567890123', 5, 3, 3, 5, 5, '5786-10-22', 9, 91.5, 'Excellent'), (15, 2, 5786, '888888888', 8, '789012345', 7, 7, 7, 7, 7, '5786-10-23', 12, 88.5, 'Very Good'); @@ -553,16 +554,16 @@ CREATE TABLE `known_absences` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO `known_absences` (`id`, `user_id`, `year`, `student_tz`, `studentReferenceId`, `klass_id`, `klassReferenceId`, `lesson_id`, `lessonReferenceId`, `report_date`, `absnce_count`, `absnce_code`, `sender_name`, `reason`, `isApproved`) VALUES -(1, 1, 5786, '222222222', 2, 1, 1, 1, 1, '5786-10-01', 1, 1, 'Parent', 'Medical appointment', 1), -(2, 1, 5786, '444444444', 4, 2, 2, 2, 2, '5786-10-01', 1, 2, 'Parent', 'Family event', 1), -(3, 2, 5786, '666666666', 6, 4, 4, 4, 4, '5786-10-02', 2, 1, 'Doctor', 'Sick', 1), -(4, 1, 5786, '999999999', 9, 7, 7, 7, 7, '5786-10-03', 2, 3, 'Parent', 'Religious holiday', 1), -(5, 1, 5786, '333333333', 3, 2, 2, 3, 3, '5786-10-05', 1, 1, 'Parent', 'Illness', 1), -(6, 2, 5786, '888888888', 8, 7, 7, 7, 7, '5786-10-08', 1, 4, 'School', 'School trip', 1), -(7, 1, 5786, '555555555', 5, 3, 3, 5, 5, '5786-10-07', 1, 2, 'Parent', 'Personal matter', 0), -(8, 1, 5786, '111111111', 1, 1, 1, 1, 1, '5786-10-10', 1, 1, 'Parent', 'Medical checkup', 1), -(9, 2, 5786, '777777777', 7, 5, 5, 5, 5, '5786-10-12', 1, 3, 'Parent', 'Family celebration', 1), -(10, 3, 5786, '121212121', 11, 9, 9, NULL, NULL, '5786-10-14', 1, 1, 'Parent', 'Cold', 1); +(1, 1, 5786, '222222222', 2, 1, 1, 1, 1, '2025-10-01', 1, 1, 'Parent', 'Medical appointment', 1), +(2, 1, 5786, '444444444', 4, 2, 2, 2, 2, '2025-10-01', 1, 2, 'Parent', 'Family event', 1), +(3, 2, 5786, '666666666', 6, 4, 4, 4, 4, '2025-10-02', 2, 1, 'Doctor', 'Sick', 1), +(4, 1, 5786, '999999999', 9, 7, 7, 7, 7, '2025-10-03', 2, 3, 'Parent', 'Religious holiday', 1), +(5, 1, 5786, '333333333', 3, 2, 2, 3, 3, '2025-10-05', 1, 1, 'Parent', 'Illness', 1), +(6, 2, 5786, '888888888', 8, 7, 7, 7, 7, '2025-10-08', 1, 4, 'School', 'School trip', 1), +(7, 1, 5786, '555555555', 5, 3, 3, 5, 5, '2025-10-07', 1, 2, 'Parent', 'Personal matter', 0), +(8, 1, 5786, '111111111', 1, 1, 1, 1, 1, '2025-10-10', 1, 1, 'Parent', 'Medical checkup', 1), +(9, 2, 5786, '777777777', 7, 5, 5, 5, 5, '2025-10-12', 1, 3, 'Parent', 'Family celebration', 1), +(10, 3, 5786, '121212121', 11, 9, 9, NULL, NULL, '2025-10-14', 1, 1, 'Parent', 'Cold', 1); -- ============================================================ -- Table: report_month @@ -590,16 +591,14 @@ CREATE TABLE `report_month` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO `report_month` (`id`, `userId`, `name`, `startDate`, `endDate`, `semester`, `year`) VALUES -(1, 1, 'September 5786', '5786-09-01', '5786-09-30', 'א', 5786), -(2, 1, 'October 5786', '5786-10-01', '5786-10-31', 'א', 5786), -(3, 1, 'November 5786', '5786-11-01', '5786-11-30', 'א', 5786), -(4, 1, 'December 5786', '5786-12-01', '5786-12-31', 'א', 5786), -(5, 2, 'September 5786', '5786-09-01', '5786-09-30', 'א', 5786), -(6, 2, 'October 5786', '5786-10-01', '5786-10-31', 'א', 5786), -(7, 1, 'Semester 1', '5786-09-01', '5786-12-31', 'א', 5786), -(8, 2, 'Semester 1', '5786-09-01', '5786-12-31', 'א', 5786), -(9, 3, 'October 5786', '5786-10-01', '5786-10-31', 'א', 5786), -(10, 3, 'November 5786', '5786-11-01', '5786-11-30', 'א', 5786); +(1, 1, 'September 2025', '2025-09-01', '2025-09-30', 'א', 5786), +(2, 1, 'October 2025', '2025-10-01', '2025-10-31', 'א', 5786), +(3, 1, 'November 2025', '2025-11-01', '2025-11-30', 'א', 5786), +(4, 1, 'December 2025', '2025-12-01', '2025-12-31', 'א', 5786), +(5, 2, 'September 2025', '2025-09-01', '2025-09-30', 'א', 5786), +(6, 2, 'October 2025', '2025-10-01', '2025-10-31', 'א', 5786), +(9, 3, 'October 2025', '2025-10-01', '2025-10-31', 'א', 5786), +(10, 3, 'November 2025', '2025-11-01', '2025-11-30', 'א', 5786); -- ============================================================ -- Table: grade_names @@ -713,16 +712,16 @@ CREATE TABLE `report_group_sessions` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO `report_group_sessions` (`id`, `userId`, `reportGroupId`, `sessionDate`, `startTime`, `endTime`, `topic`) VALUES -(1, 1, 1, '5786-10-01', '08:00:00', '09:30:00', 'Introduction to Algebra'), -(2, 1, 1, '5786-10-08', '08:00:00', '09:30:00', 'Linear equations'), -(3, 1, 2, '5786-10-02', '10:00:00', '11:30:00', 'Grammar review'), -(4, 1, 3, '5786-10-03', '13:00:00', '14:30:00', 'Reading strategies'), -(5, 2, 4, '5786-10-04', '09:00:00', '10:30:00', 'Cell structure'), -(6, 2, 5, '5786-10-05', '11:00:00', '12:30:00', 'Variables and data types'), -(7, 1, 1, '5786-10-15', '08:00:00', '09:30:00', 'Quadratic equations'), -(8, 1, 2, '5786-10-16', '10:00:00', '11:30:00', 'Essay writing'), -(9, 2, 4, '5786-10-18', '09:00:00', '10:30:00', 'Photosynthesis'), -(10, 2, 5, '5786-10-19', '11:00:00', '12:30:00', 'Control structures'); +(1, 1, 1, '2025-10-01', '08:00:00', '09:30:00', 'Introduction to Algebra'), +(2, 1, 1, '2025-10-08', '08:00:00', '09:30:00', 'Linear equations'), +(3, 1, 2, '2025-10-02', '10:00:00', '11:30:00', 'Grammar review'), +(4, 1, 3, '2025-10-03', '13:00:00', '14:30:00', 'Reading strategies'), +(5, 2, 4, '2025-10-04', '09:00:00', '10:30:00', 'Cell structure'), +(6, 2, 5, '2025-10-05', '11:00:00', '12:30:00', 'Variables and data types'), +(7, 1, 1, '2025-10-15', '08:00:00', '09:30:00', 'Quadratic equations'), +(8, 1, 2, '2025-10-16', '10:00:00', '11:30:00', 'Essay writing'), +(9, 2, 4, '2025-10-18', '09:00:00', '10:30:00', 'Photosynthesis'), +(10, 2, 5, '2025-10-19', '11:00:00', '12:30:00', 'Control structures'); SET FOREIGN_KEY_CHECKS = 1; diff --git a/server/src/migrations/1767647702833-FixDataDatesAndOverlaps.ts b/server/src/migrations/1767647702833-FixDataDatesAndOverlaps.ts new file mode 100644 index 00000000..dba17dc6 --- /dev/null +++ b/server/src/migrations/1767647702833-FixDataDatesAndOverlaps.ts @@ -0,0 +1,74 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class FixDataDatesAndOverlaps1767647702833 implements MigrationInterface { + name = 'FixDataDatesAndOverlaps1767647702833' + + public async up(queryRunner: QueryRunner): Promise { + // Check if we are in an environment with the sample data that needs fixing + // We look for a specific known sample row with the old value + const sampleRow = await queryRunner.query(` + SELECT id FROM \`report_month\` + WHERE id = 1 AND userId = 1 AND name = 'September 5786' + `); + + if (sampleRow && sampleRow.length > 0) { + // 1. Fix report_month dates and names + await queryRunner.query(` + UPDATE \`report_month\` + SET + startDate = REPLACE(startDate, '5786-', '2025-'), + endDate = REPLACE(endDate, '5786-', '2025-'), + name = REPLACE(name, '5786', '2025') + WHERE year = 5786 AND startDate LIKE '5786-%' + `); + + // 2. Remove overlapping report months (Semester 1) + await queryRunner.query(` + DELETE FROM \`report_month\` + WHERE id IN (7, 8) AND name LIKE 'Semester 1%' + `); + + // 3. Fix lessons dates + await queryRunner.query(` + UPDATE \`lessons\` + SET + start_date = REPLACE(start_date, '5786-', '2025-'), + end_date = REPLACE(end_date, '5786-', '2025-') + WHERE year = 5786 AND start_date LIKE '5786-%' + `); + + // 4. Fix att_reports dates + await queryRunner.query(` + UPDATE \`att_reports\` + SET report_date = REPLACE(report_date, '5786-', '2025-') + WHERE year = 5786 AND report_date LIKE '5786-%' + `); + + // 5. Fix grades dates + await queryRunner.query(` + UPDATE \`grades\` + SET report_date = REPLACE(report_date, '5786-', '2025-') + WHERE year = 5786 AND report_date LIKE '5786-%' + `); + + // 6. Fix known_absences dates + await queryRunner.query(` + UPDATE \`known_absences\` + SET report_date = REPLACE(report_date, '5786-', '2025-') + WHERE year = 5786 AND report_date LIKE '5786-%' + `); + + // 7. Fix report_group_sessions dates + // This table might not have a year column, so we check the date string directly + await queryRunner.query(` + UPDATE \`report_group_sessions\` + SET sessionDate = REPLACE(sessionDate, '5786-', '2025-') + WHERE sessionDate LIKE '5786-%' + `); + } + } + + public async down(queryRunner: QueryRunner): Promise { + // No easy revert for data fixes, and usually not needed for sample data correction + } +}