Skip to content

Commit

Permalink
♻️ api: refactor joi validation on simulator route
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Jeremy authored Nov 26, 2024
1 parent 9e01fe7 commit 9600327
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import Joi from 'joi';
import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js';
import { scenarioSimulatorController } from './scenario-simulator-controller.js';

const _baseScenarioParametersValidator = Joi.object().keys({
initialCapacity: Joi.number().integer().min(-8).max(8),
numberOfIterations: Joi.number().integer().min(0),
challengePickProbability: Joi.number().min(0).max(100),
variationPercent: Joi.number().min(0).max(1),
});

const register = async (server) => {
server.route([
{
Expand All @@ -26,8 +19,12 @@ const register = async (server) => {
options: {
allowUnknown: true,
},
payload: _baseScenarioParametersValidator
payload: Joi.object()
.keys({
initialCapacity: Joi.number().integer().min(-8).max(8),
numberOfIterations: Joi.number().integer().min(0),
challengePickProbability: Joi.number().min(0).max(100),
variationPercent: Joi.number().min(0).max(1),
capacity: Joi.number().min(-8).max(8).required(),
})
.required(),
Expand Down

0 comments on commit 9600327

Please sign in to comment.