Skip to content

Cover numeric validation across remaining entities (ReferenceId/int columns) - #190

Merged
buzz-code merged 6 commits into
mainfrom
fix/refid-numeric-validation-all
Sep 23, 2026
Merged

buzz-code merged 6 commits into
mainfrom
fix/refid-numeric-validation-all

Conversation

@buzz-code

@buzz-code buzz-code commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

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):

Entity Fields
AttReport studentReferenceId, teacherReferenceId, klassReferenceId, lessonReferenceId, reportGroupSessionId
Grade studentReferenceId, teacherReferenceId, klassReferenceId, lessonReferenceId, reportGroupSessionId
AttendanceCleanupRule lessonReferenceId, klassReferenceId
StudentKlass studentReferenceId, klassReferenceId
KnownAbsence studentReferenceId, klassReferenceId, lessonReferenceId
LessonSchedule teacherReferenceId, klassReferenceId, lessonReferenceId
Klass teacherReferenceId, klassTypeReferenceId
Lesson / KlassType teacherReferenceId
GradeName klassTypeReferenceId
Student year

Pattern

  • Shared IsNumber (nra-server Code improvements #58) already applies NumberType coercion, so fields only gain @IsNumber({ maxDecimalPlaces: 0 }, { always: true }) — no separate @NumberType.
  • Bare fields also get @IsOptional({ always: true }).
  • @ValidateIf predicates on *ReferenceId fields use field !== undefined && field !== null, so validation runs whenever the value is present, regardless of the sibling tz/id field — closing the both-siblings-supplied bypass.
  • String tz/id fields are untouched and keep @IsDigitsOnly.

Tests

server/src/entity-modules/__tests__/numeric-referenceid-validation.spec.ts (116 tests) mirrors the CRUD validation pipeline (plainToInstance + validate with 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 for Grade and AttReport. Full server suite: 1155/1155 pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VbiktFWAq7kz13Kz98dAX8

…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.
Copilot AI lite review requested due to automatic review settings September 16, 2026 16:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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/IsNumber decorators 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

  • NumberType converts '', whitespace, and null to 0 (server/shared/utils/entity/class-transformer.ts:4-6) before validators run. Thus required lessonReferenceId accepts an empty input because @IsNotEmpty sees 0, while nullable fields can persist 0 instead of null; 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.

Comment thread server/src/db/entities/Grade.entity.ts Resolved
Comment thread server/src/db/entities/Klass.entity.ts Resolved
Hermes Agent 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).
…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
@buzz-code
buzz-code merged commit cb840ce into main Sep 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants