Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions client/src/entities/att-report-with-report-month.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
} from 'react-admin';
import PlaylistRemoveIcon from '@mui/icons-material/PlaylistRemove';
import HelpIcon from '@mui/icons-material/Help';
import ClassIcon from '@mui/icons-material/Class';
import PersonIcon from '@mui/icons-material/Person';
import EditIcon from '@mui/icons-material/Edit';
import { CommonDatagrid } from '@shared/components/crudContainers/CommonList';
import { MultiReferenceField } from '@shared/components/fields/CommonReferenceField';
import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity';
Expand Down Expand Up @@ -77,26 +76,22 @@ const filterDefaultValues = {
export const Datagrid = ({ isAdmin, children, ...props }) => {
const additionalBulkButtons = [
<BulkActionButton
label="שינוי כיתה"
icon={<ClassIcon />}
name="bulkChangeKlass"
key="bulkChangeKlass"
label="עריכה מרוכזת"
icon={<EditIcon />}
name="bulkEdit"
key="bulkEdit"
reloadOnEnd
cacheValues={false}
>
{isAdmin && <CommonReferenceInput source="userId" reference="user" />}
{isAdmin && <CommonYearInput />}
<DateInput source="reportDate" />
<CommonReferenceInput source="klassReferenceId" reference="klass" dynamicFilter={filterByUserIdAndYear} />
</BulkActionButton>,
<BulkActionButton
label="שינוי מורה"
icon={<PersonIcon />}
name="bulkChangeTeacher"
key="bulkChangeTeacher"
reloadOnEnd
>
{isAdmin && <CommonReferenceInput source="userId" reference="user" />}
{isAdmin && <CommonYearInput />}
<CommonReferenceInput source="teacherReferenceId" reference="teacher" dynamicFilter={filterByUserId} />
<CommonReferenceInput source="lessonReferenceId" reference="lesson" dynamicFilter={filterByUserIdAndYear} />
<NumberInput source="howManyLessons" />
<NumberInput source="absCount" />
<TextInput source="comments" />
</BulkActionButton>,
<BulkActionButton label="הוספת חיסורים מאושרים" icon={<PlaylistRemoveIcon />} name="bulkKnownAbsences">
<DateInput source="reportDate" resource="known_absence" />
Expand Down
1 change: 1 addition & 0 deletions client/src/roadmapFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default [
{ html: 'דוח המורות שדיווחו: לחיצה על מספר החסרות מציגה את שמות הבנות שחסרו', status: 'בוצע', statusColor: 'success' },
{ html: 'דוח חדש "מעקב חיסורים": כרטיס לכל כיתה, סף חיסורים לבחירה, כמה חיסורים נשארו לכל תלמידה עד הסף ופירוט בלחיצה', status: 'בוצע', statusColor: 'success' },
{ html: 'מסך ההגדרות: הגדרת שם וכתובת השולח במיילים שנשלחים מהמערכת', status: 'בוצע', statusColor: 'success' },
{ html: 'רשימת דיווחי נוכחות: פעולה "עריכה מרוכזת" לשינוי תאריך, כיתה, מורה, שיעור ועוד במספר רשומות יחד (שדה ריק לא משתנה)', status: 'בוצע', statusColor: 'success' },

// { html: 'הגדרת תקופת זמן לפי תאריכים', status: 'בקרוב', statusColor: 'warning' },
// { html: 'הגדרת תקופת זמן לפי יום בשבוע', status: 'בוצע', statusColor: 'success' },
Expand Down
2 changes: 1 addition & 1 deletion server/shared
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('att-report-with-report-month.config', () => {
findBy: jest.fn(),
insert: jest.fn(),
save: jest.fn(),
update: jest.fn().mockResolvedValue({ affected: 2 }),
};
mockDataSource = {
getRepository: jest.fn().mockReturnValue(mockRepo),
Expand Down Expand Up @@ -121,5 +122,48 @@ describe('att-report-with-report-month.config', () => {
expect(mockDataSource.getRepository).toHaveBeenCalledWith(AttReport);
expect(mockBaseCreateMany).toHaveBeenCalledWith(req, dto);
});

it('bulkEdit should update only filled fields', async () => {
const req = {
parsed: {
extra: {
action: 'bulkEdit',
ids: '1,2',
reportDate: '2026-10-11',
klassReferenceId: '5',
teacherReferenceId: 'undefined',
lessonReferenceId: 'null',
howManyLessons: '',
absCount: '0',
},
},
} as any;

const result = await service.doAction(req, {});

expect(mockDataSource.getRepository).toHaveBeenCalledWith(AttReport);
expect(mockRepo.update).toHaveBeenCalledWith(
{ id: expect.anything() },
{ reportDate: new Date('2026-10-11'), klassReferenceId: 5, absCount: 0 },
);
expect(mockRepo.update.mock.calls[0][0].id.value).toEqual([1, 2]);
expect(result).toBe('עודכנו 2 רשומות');
});

it('bulkEdit should not update when no field is filled', async () => {
const req = { parsed: { extra: { action: 'bulkEdit', ids: '1,2', reportDate: 'null' } } } as any;

const result = await service.doAction(req, {});

expect(mockRepo.update).not.toHaveBeenCalled();
expect(result).toBe('לא נבחרו שדות לעדכון');
});

it('bulkEdit should reject invalid values', async () => {
const req = { parsed: { extra: { action: 'bulkEdit', ids: '1', absCount: 'abc' } } } as any;

await expect(service.doAction(req, {})).rejects.toThrow('ערך לא תקין');
expect(mockRepo.update).not.toHaveBeenCalled();
});
});
});
28 changes: 12 additions & 16 deletions server/src/entity-modules/att-report-with-report-month.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { validateBulk } from '@shared/base-entity/base-entity.util';
import { fixReferences } from '@shared/utils/entity/fixReference.util';
import { getHebrewDateFormatter } from '@shared/utils/formatting/formatter.util';
import { shouldShowTopic } from './att-report.config';
import { getBulkEditUpdate } from '@shared/utils/entity/bulkEdit.util';
import {
getAsArray,
getAsDate,
Expand Down Expand Up @@ -112,10 +113,8 @@ class AttReportWithReportMonthService<T extends Entity | AttReportWithReportMont

async doAction(req: CrudRequest<any, any>, body: any): Promise<any> {
switch (req.parsed.extra.action) {
case 'bulkChangeKlass':
return this.bulkChangeKlass(req.parsed.extra);
case 'bulkChangeTeacher':
return this.bulkChangeTeacher(req.parsed.extra);
case 'bulkEdit':
return this.bulkEdit(req.parsed.extra);
case 'bulkKnownAbsences':
return this.bulkKnownAbsences(req.parsed.extra);
case 'fixStudentReferenceV2':
Expand All @@ -126,21 +125,18 @@ class AttReportWithReportMonthService<T extends Entity | AttReportWithReportMont
return super.doAction(req, body);
}

private async bulkChangeKlass(extra: Record<string, string>): Promise<string> {
private async bulkEdit(extra: Record<string, string>): Promise<string> {
const ids = getAsNumberArray(extra.ids);
if (!ids || ids.length === 0) return 'לא נבחרו רשומות';
const klassReferenceId = getAsNumber(extra.klassReferenceId);
if (!klassReferenceId) return 'לא נבחרה כיתה';
const result = await this.dataSource.getRepository(AttReport).update({ id: In(ids) }, { klassReferenceId });
return `עודכנו ${result.affected} רשומות`;
}

private async bulkChangeTeacher(extra: Record<string, string>): Promise<string> {
const ids = getAsNumberArray(extra.ids);
if (!ids || ids.length === 0) return 'לא נבחרו רשומות';
const teacherReferenceId = getAsNumber(extra.teacherReferenceId);
if (!teacherReferenceId) return 'לא נבחר מורה';
const result = await this.dataSource.getRepository(AttReport).update({ id: In(ids) }, { teacherReferenceId });
const update = getBulkEditUpdate(extra, {
numbers: ['klassReferenceId', 'teacherReferenceId', 'lessonReferenceId', 'howManyLessons', 'absCount'],
dates: ['reportDate'],
strings: ['comments'],
});
if (Object.keys(update).length === 0) return 'לא נבחרו שדות לעדכון';

const result = await this.dataSource.getRepository(AttReport).update({ id: In(ids) }, update);
return `עודכנו ${result.affected} רשומות`;
}

Expand Down
Loading