Repository navigation
Cover numeric validation across remaining entities (ReferenceId/int columns) - #190
Merged
Merged
Conversation
…olumns) Extends the PR #186 / PR #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 #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 #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.
There was a problem hiding this comment.
🟡 Changes recommended
Moderate findings remain involving unvalidated integer fields, incomplete regression coverage, and blank/null coercion.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Extends numeric validation for integer reference fields across server entities, with regression coverage for CRUD validation behavior.
Changes:
- Adds
NumberType/IsNumberdecorators across selected entities. - Adds 84 tests covering create, update, coercion, and partial updates.
- Review findings remain for uncovered fields, test gaps, and blank/null coercion.
File summaries
| File | Summary |
|---|---|
server/src/entity-modules/__tests__/numeric-referenceid-validation.spec.ts |
Adds the numeric-validation test matrix; some field coverage remains missing. |
server/src/db/entities/StudentKlass.entity.ts |
Adds numeric validation for student and class references. |
server/src/db/entities/Student.entity.ts |
Adds numeric validation for year. |
server/src/db/entities/LessonSchedule.entity.ts |
Adds teacher-reference validation; other integer references remain flagged. |
server/src/db/entities/Lesson.entity.ts |
Adds teacher-reference numeric validation. |
server/src/db/entities/KnownAbsence.entity.ts |
Adds student/lesson validation; klassReferenceId remains flagged. |
server/src/db/entities/KlassType.entity.ts |
Adds teacher-reference numeric validation. |
server/src/db/entities/Klass.entity.ts |
Adds teacher-reference validation; klassTypeReferenceId remains flagged. |
server/src/db/entities/Grade.entity.ts |
Adds validation for several references; klassReferenceId remains flagged. |
server/src/db/entities/AttReport.entity.ts |
Adds validation for reportGroupSessionId; four existing references remain flagged. |
server/src/db/entities/AttendanceCleanupRule.entity.ts |
Adds cleanup-reference validation; blank/null coercion remains flagged. |
Review details
Suppressed comments (2)
server/src/db/entities/AttendanceCleanupRule.entity.ts:76
NumberTypeconverts'', whitespace, andnullto0(server/shared/utils/entity/class-transformer.ts:4-6) before validators run. Thus requiredlessonReferenceIdaccepts an empty input because@IsNotEmptysees0, while nullable fields can persist0instead ofnull; preserve blank/null values or validate raw input before coercion.
@NumberType
@IsNumber({ maxDecimalPlaces: 0 }, { always: true })
server/src/entity-modules/tests/numeric-referenceid-validation.spec.ts:40
- This matrix has 16 entries, not the 17 claimed by the PR, and omits
Grade.klassReferenceId, which remains an unvalidated INT reference field. The parameterized tests therefore do not catch this remaining invalid-input path. Add the missing case after adding its entity validators.
const numericFields: Array<{ entity: any; field: string }> = [
{ entity: Grade, field: 'studentReferenceId' },
{ entity: Grade, field: 'teacherReferenceId' },
{ entity: Grade, field: 'lessonReferenceId' },
{ entity: Grade, field: 'reportGroupSessionId' },
- Files reviewed: 11/11 changed files
- Comments generated: 6
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
added 2 commits
September 16, 2026 20:20
QA follow-up to PR #190: Grade.klassReferenceId was missed in the initial pass. Same placement as Grade.studentReferenceId/teacherReferenceId; its @ValidateIf predicate already includes '&& Boolean(klassReferenceId)', so partial updates omitting it keep passing. Adds the matching per-field cases to numeric-referenceid-validation.spec.ts (84 -> 89 tests).
…ling bypass QA found the same bypass PR #188 (db58962) fixed for AttReport in the sibling-gated @ValidateIf predicates: a payload supplying BOTH the tz/id sibling AND referenceId='garbage' made the predicate false, skipping @isnumber and reaching the MySQL INT column (1366 -> 500). Predicates on every *ReferenceId field now run validation whenever the value is present (field !== undefined && field !== null), regardless of the sibling tz/id field — matching db58962's exact form. The sibling-guarding @ValidateIf blocks (e.g. !Boolean(studentReferenceId) above studentTz) are untouched; @IsNotEmpty/@IsOptional kept as-is. Fields without a @ValidateIf (reportGroupSessionId x2, Student.year, Lesson/Klass/KlassType teacherReferenceId, KnownAbsence.lessonReferenceId, AttendanceCleanupRule ReferenceIds) needed no predicate change. AttReport's four ReferenceId fields also gain the @NumberType + @isnumber pair on this branch (5ce3752 added it on the unmerged PR #188; without it the predicates had no numeric validator to run, and the required both-present regression test cannot pass). Regression tests added: 'garbage' studentReferenceId rejected even when studentTz is also supplied, for Grade and AttReport (89 -> 91 tests).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VbiktFWAq7kz13Kz98dAX8
…onSchedule, GradeName) Adds @isnumber to Klass.klassTypeReferenceId, KnownAbsence.klassReferenceId, LessonSchedule.klassReferenceId/lessonReferenceId and GradeName.klassTypeReferenceId, with the present-value ValidateIf predicate, and extends the regression matrix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VbiktFWAq7kz13Kz98dAX8
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.
Summary
Extends the numeric-validation fix from #186 / #188 to every remaining entity with a numeric
ReferenceId/int column that lacked@IsNumber, so a non-numeric string now fails class-validator with a clear 400 instead of reaching the MySQL INT column as an HTTP-500.Fields covered (23 across 11 entities):
AttReportstudentReferenceId,teacherReferenceId,klassReferenceId,lessonReferenceId,reportGroupSessionIdGradestudentReferenceId,teacherReferenceId,klassReferenceId,lessonReferenceId,reportGroupSessionIdAttendanceCleanupRulelessonReferenceId,klassReferenceIdStudentKlassstudentReferenceId,klassReferenceIdKnownAbsencestudentReferenceId,klassReferenceId,lessonReferenceIdLessonScheduleteacherReferenceId,klassReferenceId,lessonReferenceIdKlassteacherReferenceId,klassTypeReferenceIdLesson/KlassTypeteacherReferenceIdGradeNameklassTypeReferenceIdStudentyearPattern
IsNumber(nra-server Code improvements #58) already appliesNumberTypecoercion, so fields only gain@IsNumber({ maxDecimalPlaces: 0 }, { always: true })— no separate@NumberType.@IsOptional({ always: true }).@ValidateIfpredicates on*ReferenceIdfields usefield !== undefined && field !== null, so validation runs whenever the value is present, regardless of the sibling tz/id field — closing the both-siblings-supplied bypass.@IsDigitsOnly.Tests
server/src/entity-modules/__tests__/numeric-referenceid-validation.spec.ts(116 tests) mirrors the CRUD validation pipeline (plainToInstance+validatewith CREATE/UPDATE groups): non-numeric string rejected on create/update, integer accepted, numeric string coerced, partial updates omitting the field pass; plus sibling-bypass regressions forGradeandAttReport. Full server suite: 1155/1155 pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01VbiktFWAq7kz13Kz98dAX8