import { ParamSchema , Schema } from 'express-validator' ; export const inQuery = { in : [ 'query' ] } ; export const inParams = { in : [ 'params' ] } ; export const inBody = { in : [ 'body' ] } ; export const isRequired = { notEmpty : true } ; export const isOptional = { optional : { options : { nullable : true } } , } ; export const isNaturalNumber = { isNumeric : { options : { no_symbols : true } } , } ; export const isNumeric = { isNumeric : true } ; export const isBoolean = { isBoolean : true } ; export const isDateTime = { isISO8601 : { options : { strict : true , strictSeparator : true } } , } ; export const isIn = ( valueList ) : ParamSchema => { return { isIn : { options : [ valueList ] } , errorMessage : `Invalid value. Allowed values: ${ valueList }` , } ; } ; export const equals = ( text ) : ParamSchema => { return { equals : { options : [ text ] } , errorMessage : `Invalid value. Value should be '${ text }'` , } ; } ; export const toInt = { toInt : true } ; export const pageParamSchema = { ... inQuery , ... isOptional , ... isNaturalNumber , ... toInt , } ; export const pageSizeParamSchema = pageParamSchema ; export function getOptionalSchema ( schema ) { for ( const field of Object . keys ( schema ) ) { const validations = schema [ field ] ; delete validations . notEmpty ; if ( ! ( 'optional' in validations ) ) { schema [ field ] = { ... validations , ... isOptional } ; } } return schema ; }