From 439d8141931a5e71eba31b5d77e5468d6d942963 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 5 Sep 2026 18:49:29 +0000 Subject: [PATCH 1/3] Support multiple emails per teacher Teacher.email is now a string array instead of a single address, so a teacher can be reached at more than one address (like the existing phone/phone2 pair, but as a real array since it's actually sent to, not just displayed): - Teacher.entity.ts: email column is `simple-array`, validated as an array of email addresses; a plain comma-separated string (e.g. from Excel import) is normalized into an array before validation and before save. - Datagrid shows each address as its own EmailField; the edit form uses ArrayInput/SimpleFormIterator to add/remove addresses. - Export joins the addresses into a comma-separated string. - Migration widens the column from varchar(500) to text in place (existing single-address values remain valid). - Bumps server/shared to pick up sendBulkTeacherMailWithFile sending to every address in the array (still backward compatible with a plain string). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Qta52umWJRr3CBuj4XVfCV --- client/src/entities/teacher.jsx | 19 ++++++++++++-- server/shared | 2 +- server/src/db/entities/Teacher.entity.ts | 26 +++++++++++++++---- .../__tests__/teacher.config.spec.ts | 10 ++++++- server/src/entity-modules/teacher.config.ts | 2 +- ...788633251783-ConvertTeacherEmailToArray.ts | 18 +++++++++++++ 6 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 server/src/migrations/1788633251783-ConvertTeacherEmailToArray.ts diff --git a/client/src/entities/teacher.jsx b/client/src/entities/teacher.jsx index 9c13f4de..1ff4c4a6 100644 --- a/client/src/entities/teacher.jsx +++ b/client/src/entities/teacher.jsx @@ -1,11 +1,15 @@ import { + ArrayInput, DateField, DateInput, DateTimeInput, + email, EmailField, + FunctionField, maxLength, ReferenceField, required, + SimpleFormIterator, TextField, TextInput, } from 'react-admin'; @@ -34,7 +38,14 @@ const Datagrid = ({ isAdmin, children, ...props }) => { - + [].concat(record.email ?? []).map((addr) => ( +
+ +
+ ))} + /> {isAdmin && } {isAdmin && } @@ -54,7 +65,11 @@ const Inputs = ({ isCreate, isAdmin }) => { - + + + + + {!isCreate && isAdmin && } {!isCreate && isAdmin && } diff --git a/server/shared b/server/shared index 45e33fc8..46929482 160000 --- a/server/shared +++ b/server/shared @@ -1 +1 @@ -Subproject commit 45e33fc80b31d6f810f0966c4e23f17ff937ccb2 +Subproject commit 46929482527f120147276f4174d6668b8b7c235f diff --git a/server/src/db/entities/Teacher.entity.ts b/server/src/db/entities/Teacher.entity.ts index bc3fbfdf..8115ad1d 100644 --- a/server/src/db/entities/Teacher.entity.ts +++ b/server/src/db/entities/Teacher.entity.ts @@ -1,7 +1,8 @@ import { BeforeInsert, BeforeUpdate, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { IHasUserId } from '@shared/base-entity/interface'; import { User } from 'src/db/entities/User.entity'; -import { IsOptional } from 'class-validator'; +import { IsArray, IsEmail, IsOptional } from 'class-validator'; +import { Transform } from 'class-transformer'; import { CrudValidationGroups } from '@dataui/crud'; import { IsNotEmpty, IsUniqueCombination, MaxLength } from '@shared/utils/validation/class-validator-he'; import { StringType } from '@shared/utils/entity/class-transformer'; @@ -21,6 +22,12 @@ export class Teacher implements IHasUserId { if (this.number === '') this.number = null; } + @BeforeInsert() + @BeforeUpdate() + normalizeEmail() { + this.email = splitEmails(this.email); + } + @PrimaryGeneratedColumn({ type: 'int', name: 'id' }) id: number; @@ -65,10 +72,11 @@ export class Teacher implements IHasUserId { number: string | null; @IsOptional({ always: true }) - @StringType - @MaxLength(500, { always: true }) - @Column('varchar', { name: 'email', nullable: true, length: 500 }) - email: string | null; + @IsArray({ always: true }) + @IsEmail({}, { each: true, always: true }) + @Transform(({ value }) => splitEmails(value)) + @Column('simple-array', { name: 'email', nullable: true }) + email: string[] | null; @IsOptional({ always: true }) @StringType @@ -95,3 +103,11 @@ export class Teacher implements IHasUserId { @JoinColumn([{ name: 'user_id', referencedColumnName: 'id' }]) user: User; } + +function splitEmails(value: unknown): string[] | null { + if (typeof value !== 'string') return value as string[] | null; + return value + .split(',') + .map((e) => e.trim()) + .filter(Boolean); +} diff --git a/server/src/entity-modules/__tests__/teacher.config.spec.ts b/server/src/entity-modules/__tests__/teacher.config.spec.ts index 8f649f6a..f9af2232 100644 --- a/server/src/entity-modules/__tests__/teacher.config.spec.ts +++ b/server/src/entity-modules/__tests__/teacher.config.spec.ts @@ -16,9 +16,17 @@ describe('TeacherConfig', () => { { value: 'name', label: 'שם' }, { value: 'phone', label: 'טלפון' }, { value: 'phone2', label: 'טלפון 2' }, - { value: 'email', label: 'כתובת מייל' }, + { value: expect.any(Function), label: 'כתובת מייל' }, { value: 'displayName', label: 'שם לתצוגה' }, ]), ); }); + + it('should join teacher emails into a comma separated string for export', () => { + const headers = teacherConfig.exporter.getExportHeaders([]); + const emailHeader = headers.find((h: any) => h.label === 'כתובת מייל') as any; + + expect(emailHeader.value({ email: ['a@example.com', 'b@example.com'] })).toBe('a@example.com, b@example.com'); + expect(emailHeader.value({ email: null })).toBe(''); + }); }); diff --git a/server/src/entity-modules/teacher.config.ts b/server/src/entity-modules/teacher.config.ts index 17e374c4..23825ab4 100644 --- a/server/src/entity-modules/teacher.config.ts +++ b/server/src/entity-modules/teacher.config.ts @@ -13,7 +13,7 @@ function getConfig(): BaseEntityModuleOptions { { value: 'number', label: 'מספר מורה' }, { value: 'phone', label: 'טלפון' }, { value: 'phone2', label: 'טלפון 2' }, - { value: 'email', label: 'כתובת מייל' }, + { value: (record: any) => (record.email ?? []).join(', '), label: 'כתובת מייל' }, { value: 'displayName', label: 'שם לתצוגה' }, ]; }, diff --git a/server/src/migrations/1788633251783-ConvertTeacherEmailToArray.ts b/server/src/migrations/1788633251783-ConvertTeacherEmailToArray.ts new file mode 100644 index 00000000..e25bf2d7 --- /dev/null +++ b/server/src/migrations/1788633251783-ConvertTeacherEmailToArray.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class ConvertTeacherEmailToArray1788633251783 implements MigrationInterface { + name = 'ConvertTeacherEmailToArray1788633251783' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE \`teachers\` MODIFY COLUMN \`email\` text NULL + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE \`teachers\` MODIFY COLUMN \`email\` varchar(500) NULL + `); + } + +} From 20fb0d74696b1d48c4018960d313aff992b78615 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 5 Sep 2026 19:00:12 +0000 Subject: [PATCH 2/3] Address review: email input type, merge normalize hooks - email array input uses type="email" (proper keyboard/semantics, not a plain text box) - merge normalizeNumber/normalizeEmail into one BeforeInsert/ BeforeUpdate hook - no need for two separate ones Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Qta52umWJRr3CBuj4XVfCV --- client/src/entities/teacher.jsx | 2 +- server/src/db/entities/Teacher.entity.ts | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/client/src/entities/teacher.jsx b/client/src/entities/teacher.jsx index 1ff4c4a6..73fd69b4 100644 --- a/client/src/entities/teacher.jsx +++ b/client/src/entities/teacher.jsx @@ -67,7 +67,7 @@ const Inputs = ({ isCreate, isAdmin }) => { - + diff --git a/server/src/db/entities/Teacher.entity.ts b/server/src/db/entities/Teacher.entity.ts index 8115ad1d..706743bd 100644 --- a/server/src/db/entities/Teacher.entity.ts +++ b/server/src/db/entities/Teacher.entity.ts @@ -18,13 +18,8 @@ import { CreatedAtColumn, UpdatedAtColumn } from '@shared/utils/entity/column-ty export class Teacher implements IHasUserId { @BeforeInsert() @BeforeUpdate() - normalizeNumber() { + normalizeFields() { if (this.number === '') this.number = null; - } - - @BeforeInsert() - @BeforeUpdate() - normalizeEmail() { this.email = splitEmails(this.email); } From 9636773e95f71a5bd64b730e73e9a5fcfdbc2426 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 5 Sep 2026 19:02:56 +0000 Subject: [PATCH 3/3] Bump server/shared to merged nra-server main Points at buzz-code/nra-server#51 (sendBulkTeacherMailWithFile multi-email support), now merged to main. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Qta52umWJRr3CBuj4XVfCV --- server/shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/shared b/server/shared index 46929482..332a24fe 160000 --- a/server/shared +++ b/server/shared @@ -1 +1 @@ -Subproject commit 46929482527f120147276f4174d6668b8b7c235f +Subproject commit 332a24fed4af74dbf356b694d5609fe2937a2f46