Skip to content

fix: coerce numeric values to strings in IsDigitsOnly - #56

Closed
buzz-code wants to merge 1 commit into
mainfrom
fix/isdigitsonly-string-coercion
Closed

buzz-code wants to merge 1 commit into
mainfrom
fix/isdigitsonly-string-coercion

Conversation

@buzz-code

Copy link
Copy Markdown
Owner

Problem

Excel/CSV bulk uploads (e.g. the lessons import) send numeric cells as JSON numbers, but fields decorated with @IsDigitsOnly expect a string. Result: every row of a bulk upload fails validation.

Root cause

IsDigitsOnly is a string validator with no type transform. A numeric teacherId (e.g. 12345) fails the typeof value !== 'string' check.

Fix (in the shared validator, not per-entity)

Wrap IsDigitsOnly with applyDecorators so it also carries a Transform that coerces any finite number to its string form before validation — functionally identical to the explicit @StringType already used on Teacher.tz/Student.tz, but embedded so every @IsDigitsOnly field 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 @StringType additions needed.

Behavior

  • Only typeof value === 'number' && Number.isFinite(value) converts; every other type passes through unchanged.
  • Existing blank (undefined/null/'') passthrough is preserved.

Test Plan

  • New spec: plainToInstance(Test, { key: 12345 }) \u2192 '12345', validate passes.
  • 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 no CONSUMER_CHANGES.md row).

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

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.

🟢 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.

@buzz-code

Copy link
Copy Markdown
Owner Author

Superseded by #57 (re-applied on top of current main after PR #54 moved IsDigitsOnly into its own file).

@buzz-code buzz-code closed this Sep 16, 2026
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.

2 participants