Repository navigation
Add IsDigitsOnly validator for varchar ID/number fields - #53
Merged
Merged
Conversation
Some entity fields (a TZ/ID number, a business "number") must stay varchar rather than a numeric-typed column, to preserve leading zeros. That put them out of reach of the existing numeric validators here, so they had no format validation beyond length/presence. IsDigitsOnly rejects a non-digit string but passes through undefined/null/'' (presence stays @isnotempty's job, as with every other validator in this file), with an optional max length for fields that don't already have one. Follows the file's conventions: Hebrew message via getErrorMessageFunction, wraps class-validator's ValidateBy the same way every other export here wraps its underlying decorator. 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
The new validator’s error message can be misleading when failing due to maxLength, and the added test claims to cover null without actually testing it.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a new shared validation decorator to enforce “digits-only” semantics on varchar ID/number fields that must remain strings (e.g., leading-zero identifiers), along with Jest coverage in the shared validation test suite.
Changes:
- Added
IsDigitsOnly(maxLength?, validationOptions?)toutils/validation/class-validator-he.tsusing the existing Hebrew error-message wrapper. - Added a dedicated
describe('IsDigitsOnly')block inutils/validation/__tests__/class-validator-he.spec.ts.
File summaries
| File | Description |
|---|---|
| utils/validation/class-validator-he.ts | Introduces IsDigitsOnly via ValidateBy, with optional max-length enforcement and Hebrew message handling. |
| utils/validation/tests/class-validator-he.spec.ts | Adds unit tests validating pass-through behavior and rejection of non-digit strings, plus max-length enforcement. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- 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 on lines
+59
to
+63
| return max === undefined || value.length <= max; | ||
| }, | ||
| }, | ||
| }, | ||
| { ...validationOptions, message: getErrorMessageFunction('$property חייב להכיל ספרות בלבד $value') }, |
Comment on lines
+157
to
+168
| it('should not return an error message for undefined, null or an empty string', async () => { | ||
| class Test { | ||
| @IsDigitsOnly() key: string; | ||
| } | ||
|
|
||
| const test = new Test(); | ||
| const result = await validate(test); | ||
| expect(result).toEqual([]); | ||
|
|
||
| test.key = ''; | ||
| expect(await validate(test)).toEqual([]); | ||
| }); |
buzz-code
pushed a commit
to buzz-code/react-admin-nestjs
that referenced
this pull request
Sep 9, 2026
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
TziporaStern
pushed a commit
to TziporaStern/nra-server
that referenced
this pull request
Oct 17, 2026
Follows the IsUniqueCombination / IsUniqueDateRange / MaxCountByUserLimit pattern: the raw decorator lives in its own file using registerDecorator, class-validator-he.ts just wraps it with the Hebrew message. Dropped the verbose block comment and the redundant IsDigitsOnly tests in class-validator-he.spec.ts (IsUniqueCombination/IsUniqueDateRange aren't tested there either) in favor of a dedicated is-digits-only.spec.ts. No behavior change from PR buzz-code#53. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016mY7oyUH46UtvEKekiF7fT
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.
Why
Consumer app react-admin-nestjs (buzz-code/react-admin-nestjs#186) needs format validation on varchar ID/number fields (TZ numbers, a teacher/klass "number") that must stay strings to preserve leading zeros — so they're out of reach of the existing numeric validators in
class-validator-he.ts.What
Adds
IsDigitsOnly(maxLength?, validationOptions?)toutils/validation/class-validator-he.ts, following this file's conventions: wrapsclass-validator'sValidateBythe same way every other export here wraps its underlying decorator, Hebrew message via the existinggetErrorMessageFunction. Passes throughundefined/null/''(presence stays@IsNotEmpty's job); optionally enforces a max length for fields that don't already have a separate@MaxLength.Purely additive — no existing export changed, no consumer action required, so no
CONSUMER_CHANGES.mdrow per this repo's own convention.Testing
Added unit tests in
utils/validation/__tests__/class-validator-he.spec.tsfollowing the existing per-decoratordescribeblock pattern. Verified via the react-admin-nestjs consumer checkout (this repo has no standalone test runner of its own — it's consumed as a submodule): 20/20 tests pass,tsc --noEmitclean.🤖 Generated with Claude Code
https://claude.ai/code/session_016mY7oyUH46UtvEKekiF7fT
Generated by Claude Code