Repository navigation
Conversation
Excel/CSV bulk uploads send numeric cells as JSON numbers, but fields decorated with @IsDigitsOnly expect a string. Every such entity failed validation on a bulk import. Add a @StringType-equivalent Transform to IsDigitsOnly so any field using it gets the numeric->string coercion for free, instead of repeating @StringType on each entity. Also add a spec proving plainToInstance turns 12345 into '12345' and validate passes.
There was a problem hiding this comment.
🟢 Approval recommended
The shared validator fix includes regression coverage and has no unresolved issues.
Pull request overview
Updates IsDigitsOnly to coerce finite numeric inputs to strings, fixing validation for numeric Excel/CSV upload values.
Changes:
- Added numeric-to-string transformation.
- Added regression tests for coercion and validation.
File summaries
| File | Summary |
|---|---|
utils/validation/class-validator-he.ts |
Adds the shared numeric coercion transform. |
utils/validation/__tests__/class-validator-he.spec.ts |
Tests numeric coercion and validation. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Owner
Author
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/CSV bulk uploads (e.g. the lessons import) send numeric cells as JSON
numbers, but fields decorated with@IsDigitsOnlyexpect a string. Result: every row of a bulk upload fails validation.Root cause
IsDigitsOnlyis a string validator with no type transform. A numericteacherId(e.g.12345) fails thetypeof value !== 'string'check.Fix (in the shared validator, not per-entity)
Wrap
IsDigitsOnlywithapplyDecoratorsso it also carries aTransformthat coerces any finitenumberto its string form before validation — functionally identical to the explicit@StringTypealready used onTeacher.tz/Student.tz, but embedded so every@IsDigitsOnlyfield gets it automatically.Fields this fixes across all consumer apps:
Lesson.teacherId,Grade.studentTz/Grade.teacherId,AttReport.studentTz/AttReport.teacherId,Klass.teacherId,KlassType.teacherId,KnownAbsence.studentTz,LessonSchedule.teacherId— no per-entity@StringTypeadditions needed.Behavior
typeof value === 'number' && Number.isFinite(value)converts; every other type passes through unchanged.Test Plan
plainToInstance(Test, { key: 12345 })\u2192'12345',validatepasses.class-validator-he.spec.ts: 21/21 pass.Note
This is a purely additive change in
nra-server— works automatically on submodule bump, no per-app action required (so noCONSUMER_CHANGES.mdrow).