Repository navigation
Add numeric validation to Excel-uploaded fields missing it - #186
Merged
Merged
Conversation
Audit of every entity reachable via Excel import (UI import button and mail-attachment auto-import) found two gaps where a string value would pass class-validator and crash at the DB layer instead of returning a clear validation error: - year: number columns on AbsenceType, AttReport, Grade, Klass, KnownAbsence, Lesson, LessonSchedule, ReportMonth, Teacher, Transportation had no validation decorators at all. - ReportGroup (teacherReferenceId, lessonReferenceId, klassReferenceId, year) and ReportGroupSession (reportGroupId) had @NumberType (a transform) but no @isnumber (the actual validator). All other numeric fields already followed the established @NumberType + @isnumber pattern (see StudentKlass.year for the existing correct example). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016mY7oyUH46UtvEKekiF7fT
There was a problem hiding this comment.
🟡 Changes recommended
Added @IsNumber(..., { always: true }) on ReportGroupSession.reportGroupId can break UPDATE/PATCH validation when field omitted (missing @IsOptional for UPDATE group).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Add missing numeric validation decorators on integer fields populated via Excel import, so bad string inputs fail validation (Hebrew message) instead of reaching DB layer and throwing internal error.
Changes:
- Add
@IsOptional({ always: true }) @NumberType @IsNumber({ maxDecimalPlaces: 0 }, { always: true })to multiple nullableyearcolumns. - Add missing
@IsNumbervalidations toReportGroupreference-id fields andReportGroupSession.reportGroupId. - Update entity imports to include
IsNumber/NumberTypewhere needed.
File summaries
| File | Description |
|---|---|
| server/src/db/entities/Transportation.entity.ts | Add numeric validation for nullable year. |
| server/src/db/entities/Teacher.entity.ts | Add numeric validation for nullable year; update imports. |
| server/src/db/entities/ReportMonth.entity.ts | Add numeric validation for nullable year; update imports. |
| server/src/db/entities/ReportGroupSession.entity.ts | Add @IsNumber validation for reportGroupId. |
| server/src/db/entities/ReportGroup.entity.ts | Add @IsOptional + @IsNumber for reference ids and year; update imports. |
| server/src/db/entities/LessonSchedule.entity.ts | Add numeric validation for nullable year. |
| server/src/db/entities/Lesson.entity.ts | Add numeric validation for nullable year. |
| server/src/db/entities/KnownAbsence.entity.ts | Add numeric validation for nullable year. |
| server/src/db/entities/Klass.entity.ts | Add numeric validation for nullable year. |
| server/src/db/entities/Grade.entity.ts | Add numeric validation for nullable year. |
| server/src/db/entities/AttReport.entity.ts | Add numeric validation for nullable year. |
| server/src/db/entities/AbsenceType.entity.ts | Add numeric validation for nullable year. |
Review details
- Files reviewed: 12/12 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Teacher.tz/number, Student.tz/studentNumber, and the studentTz/teacherId business-key fields on Grade, AttReport, KnownAbsence, StudentKlass, Klass, Lesson, LessonSchedule and KlassType are varchar (kept as strings to preserve leading zeros in Israeli ID numbers), so they were out of scope for the earlier numeric-column fix. They still had no format validation though — some were missing @maxlength entirely (Klass, Lesson, KlassType teacherId had zero validators) — so a non-digit or oversized value would only surface as a raw DB error. Added a new IsDigitsOnly validator (server/src/utils/validation) that: - passes through undefined/null/'' (presence stays @isnotempty's job) - rejects anything but digits when a value is present - optionally enforces max length, for the fields missing @maxlength Kept local to this repo per its own guidance (server/shared is a separate submodule) rather than extending class-validator-he.ts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016mY7oyUH46UtvEKekiF7fT
class-validator's MaxLength (like IsNumberString before it) returns false for any non-string value, undefined included — it isn't blank-tolerant. Pairing it directly on teacherId/studentTz fields that have no value in a given request (a create that leaves teacherId blank, a partial update that doesn't touch studentTz) made those requests fail validation outright, which is exactly what broke the klass_type E2E create test in CI. Fold the length check into IsDigitsOnly's own maxLength parameter instead (already blank-tolerant by design) and drop the standalone @maxlength on the fields where I'd added it fresh (Grade, AttReport, KnownAbsence studentTz/teacherId; Klass, Lesson, LessonSchedule, KlassType teacherId). Fields that already had a working @maxlength before this change (Teacher, Student, StudentKlass) are untouched. Verified with a standalone class-validator run: create/update payloads that omit these fields validate clean again, and a non-digit value still gets rejected. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016mY7oyUH46UtvEKekiF7fT
Copilot review flagged it (PR #186): @isnumber({always:true}) with no matching @IsOptional for the UPDATE group meant a PATCH that doesn't touch reportGroupId (e.g. updating just topic) failed validation on the resulting undefined value. Added @IsOptional({groups:[UPDATE]}), matching the create-required/update-optional pattern used elsewhere (e.g. Klass.key). CREATE still rejects missing/non-numeric values; UPDATE now passes when the field is simply not part of the payload. Verified directly against class-validator: CREATE without/garbage reportGroupId still fails, UPDATE omitting it now passes, UPDATE with a bad value still fails. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016mY7oyUH46UtvEKekiF7fT
Per feedback: this validator belongs alongside the other Hebrew-message class-validator wrappers in shared/utils/validation/class-validator-he.ts, not as a one-off local file. Moved it there (buzz-code/nra-server#53, merged), bumped the server/shared submodule pointer, and switched every entity that used the local src/utils/validation/numeric-string.util import over to the shared one. Deleted the local file and its test — the equivalent test now lives in nra-server's own class-validator-he.spec.ts. No behavior change: same validator, same call sites, now using the shared getErrorMessageFunction/translationDict machinery for its error message instead of a hardcoded string. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016mY7oyUH46UtvEKekiF7fT
This was referenced Sep 16, 2026
TziporaStern
pushed a commit
to TziporaStern/react-admin-nestjs
that referenced
this pull request
Oct 17, 2026
…olumns) Extends the PR buzz-code#186 / PR buzz-code#188 @NumberType + @isnumber({maxDecimalPlaces:0}) fix to the numeric ReferenceId/int columns still missing it, so a non-numeric string fails class-validator with a clear 400 instead of reaching the MySQL INT column as an HTTP-500: - AttReport.reportGroupSessionId, Grade.reportGroupSessionId - Grade: studentReferenceId, teacherReferenceId, lessonReferenceId - AttendanceCleanupRule: lessonReferenceId, klassReferenceId - StudentKlass: studentReferenceId, klassReferenceId - KnownAbsence: studentReferenceId, lessonReferenceId - Lesson/LessonSchedule/Klass/KlassType: teacherReferenceId - Student.year Bare fields get the full PR buzz-code#186 pattern (@IsOptional({always:true}) + pair); fields with existing @ValidateIf/@IsNotEmpty/@IsOptional keep them and only gain the @NumberType + @isnumber pair right before @column, matching the placement PR buzz-code#188 used on AttReport. The ValidateIf predicates all include '&& Boolean(field)', so omitted values skip validation and partial updates keep passing. New spec mirrors the CRUD validation pipeline (plainToInstance + validate with CREATE/UPDATE groups): garbage rejected on create and update, integers and numeric strings (NumberType coercion) accepted, partial updates omitting the fields still pass, plus full-payload create scenarios for Grade and Student.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Excel upload complaints: uploading string where numeric value expected. No clean validation error — just internal error.
Cause
Audited every entity reachable via Excel import (UI import button + mail-attachment auto-import). Two gap patterns found where a bad string bypasses class-validator and hits the DB layer raw:
year: numbercolumns with zero validation decorators — AbsenceType, AttReport, Grade, Klass, KnownAbsence, Lesson, LessonSchedule, ReportMonth, Teacher, Transportation. (StudentKlass already had the correct pattern — used as reference.)@NumberTypepresent but@IsNumbermissing (transform without validator) — ReportGroup (teacherReferenceId,lessonReferenceId,klassReferenceId,year) and ReportGroupSession (reportGroupId).Every other numeric field already had
@NumberType+@IsNumber— no other gaps found.Fix
Added
@IsOptional({ always: true }) @NumberType @IsNumber({ maxDecimalPlaces: 0 }, { always: true })(matching the existing house pattern) to each field above. Non-numeric Excel values now fail validation with a clear Hebrew error message (via the existingclass-validator-hewrapper) instead of an internal DB error.Testing
yarn tsc --noEmit— cleanyarn test— 117 suites / 1030 tests pass🤖 Generated with Claude Code
https://claude.ai/code/session_016mY7oyUH46UtvEKekiF7fT
Generated by Claude Code