Skip to content

Commit ff540af

Browse files
committed
[O2B-1505] Fixed validateTime error handling, removed unused code, TODO validate tests
1 parent 9e3bc30 commit ff540af

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

lib/domain/dtos/filters/NumericalComparisonDto.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ exports.FloatComparisonDto = Joi.object({
2424
operator: Joi.string().valid(...NUMERICAL_COMPARISON_OPERATORS),
2525
limit: Joi.number().min(0),
2626
});
27+
28+
exports.NUMERICAL_COMPARISON_OPERATORS = NUMERICAL_COMPARISON_OPERATORS;

lib/public/views/LhcFills/LhcFills.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class LhcFills extends Observable {
2929
this.model = model;
3030

3131
// Sub-models
32-
this._overviewModel = new LhcFillsOverviewModel(model, true);
32+
this._overviewModel = new LhcFillsOverviewModel(true);
3333
this._overviewModel.bubbleTo(this);
3434

3535
this._detailsModel = new LhcFillDetailsModel();

lib/public/views/LhcFills/Overview/LhcFillsOverviewModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class LhcFillsOverviewModel extends OverviewPageModel {
3131
* @param {model} model global model
3232
* @param {boolean} [stableBeamsOnly=false] if true, overview will load stable beam only
3333
*/
34-
constructor(model, stableBeamsOnly = false) {
34+
constructor(stableBeamsOnly = false) {
3535
super();
3636

3737
this._filteringModel = new FilteringModel({

lib/utilities/validateTime.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,30 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313
import Joi from 'joi';
14+
import { NUMERICAL_COMPARISON_OPERATORS } from '../domain/dtos/filters/NumericalComparisonDto.js';
1415

1516
const joiTimeDurationErrorText = 'Invalid duration value';
1617

1718
/**
1819
* Transform digital time in string format
1920
*
20-
* @param {*} incomingValue The time to transform
21-
* @returns {number} The value as seconds (Number)
21+
* @param {string} incomingValue The time to transform
22+
* @param {*} helpers The Joi helpers object
23+
* @returns {number|import("joi").ValidationError} The value if transformation passes, as seconds (Number)
2224
*/
23-
export const transformTime = (incomingValue) => {
24-
// Extract time to seconds...
25-
const [hoursStr, minutesStr, secondsStr] = incomingValue.split(':');
25+
export const transformTime = (incomingValue, helpers) => {
26+
try {
27+
// Extract time to seconds...
28+
const [hoursStr, minutesStr, secondsStr] = incomingValue.split(':');
2629

27-
return Number(hoursStr) * 3600 + Number(minutesStr) * 60 + Number(secondsStr);
30+
const hours = Number(hoursStr);
31+
const minutes = Number(minutesStr);
32+
const seconds = Number(secondsStr);
33+
34+
return hours * 3600 + minutes * 60 + seconds;
35+
} catch (error) {
36+
return helpers.error('any.invalid', { message: `Validation error: ${error?.message ?? 'failed to transform time'}` });
37+
}
2838
};
2939

3040
/**
@@ -36,7 +46,6 @@ export const validateTimeDuration = Joi.object({
3646
limit: Joi.string().trim().pattern(/^\d+:[0-5]?\d:[0-5]?\d$/).custom(transformTime).messages({
3747
'string.pattern.base': joiTimeDurationErrorText,
3848
'string.base': joiTimeDurationErrorText,
39-
'any.invalid': joiTimeDurationErrorText,
4049
}),
41-
operator: Joi.string().trim().min(1).max(2),
50+
operator: Joi.string().valid(...NUMERICAL_COMPARISON_OPERATORS),
4251
});

0 commit comments

Comments
 (0)