-
Notifications
You must be signed in to change notification settings - Fork 23
[O2B-1602] Shared BeamTypesDto should return split input rather than simply validation #2202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1e8d30e
ded1c12
15fdc9c
b9334a3
67dd8a3
33cf287
a35a5e8
11a0a33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,12 +12,34 @@ | |
| */ | ||
|
|
||
| const Joi = require('joi'); | ||
| const { validateBeamTypes, BEAM_TYPE_INVALID } = require('../../../utilities/beamTypeUtils'); | ||
| const { CustomJoi } = require('../CustomJoi.js'); | ||
|
|
||
| exports.BeamTypesDto = Joi.string() | ||
| .trim() | ||
| .custom(validateBeamTypes) | ||
| .messages({ | ||
| [BEAM_TYPE_INVALID]: '{{#message}}', | ||
| 'string.base': 'Beam type must be a string', | ||
| }); | ||
| /** | ||
| * @typedef {string[]} BeamTypesDto | ||
| * @description An array of beam types, each represented as a string. | ||
| * Each beam type must be a string with a minimum length of 2 characters and a maximum length of 15 characters. | ||
| * The string must match patterns such as "PROTON - PROTON", "NE10 - NE10", where the two parts are separated by a hyphen and optional spaces. | ||
| * | ||
| * RUN3 has the following beam types: | ||
| * "PROTON - PROTON" | ||
| * "NE10 - NE10" | ||
| * "O8 - O8" | ||
| * "PB82 - PB82" | ||
| * "PROTON - O8" | ||
| * "PROTON - PROTON" | ||
| * | ||
| * @example | ||
| * const beamTypes = ["PROTON - PROTON", "NE10 - NE10"]; | ||
| */ | ||
| exports.BeamTypesDto = CustomJoi.stringArray() | ||
| .items(Joi.string() | ||
| .trim() | ||
| .min(2) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this minimum check necessary as the pattern enforces >2 chars with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the pattern will enforce that, I think it is also important to be self-explanatory when writing code, so that it is easy to maintain it. |
||
| .max(15) | ||
| .pattern(/^[A-Za-z0-9]+ ?- ?[A-Za-z0-9]+$/) | ||
| .messages({ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The custom validator was the only thing raising Supported by the fact the Do you agree?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct. I have modified the DTO to have more specific error messages now |
||
| 'string.base': 'Beam type must be a string', | ||
| 'string.min': 'Beam type must be at least 2 characters long', | ||
| 'string.max': 'Beam type must be at most 15 characters long', | ||
| 'string.pattern.base': 'Beam type must look like "PROTON - PROTON", "NE10 - NE10", etc.', | ||
| })); | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand this was not introduced in this PR, so not to be implemented here, but would you agree that
CustomJoiis a rather nondescript name and should be changed to something like `StringArrayJoi? If so, I will make a note and then the change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not believe it should be changed to "StringArrayJoi" because the name CustomJoi refers to the wrapper defined in that file.
If you look at the implementation of the wrapper, you will see it defines the method
stringArraywhich is being called in this file.Thus, to me: