validation/JoiMessages.js
/**
 * msg - Create a list of error Codes and custom messages for Joi schemas,
 * customized based on the parameters
 *
 * @param {String} name - Descriptive name of the input field
 * @param {String} type - the Joi type of the field
 * @param {Array} errorNames - List of standard Joi error names
 * @return {Object}
 */
Create a list of error Codes and custom messages for Joi schemas,
customized based on the parameters

@param {String} name - Descriptive name of the input field
@param {String} type - the Joi type of the field
@param {Array} errorNames - List of standard Joi error names
@return {Object}
Create a list of error Codes and custom messages for Joi schemas customized based on the parameters @param { String } name - Descriptive name of the input field @param { String } type - the Joi type of the field @param { Array } errorNames - List of standard Joi error names @return { Object }
function msg(name, type, errorNames) {
  name = name.charAt(0).toUpperCase() + name.slice(1)
  let errorObject = {}
  errorObject[`${type}.base`] = messages[`${type}.base`].replace('<name>', name)
  if (errorNames && errorNames.length > 0) {
    for (const errorName of errorNames) {
      let errorCode = `${type}.${errorName}`
      if (errorName == 'required') errorCode = 'any.required'
      if (!messages[errorCode]) {
        console.log(
          `ERROR: JoiMessages: errorCode '${errorCode}' does not exist in list.`
        )
        errorObject[errorCode] = `Error in '${errorCode}'`
      } else {
        errorObject[errorCode] = messages[errorCode].replace('<name>', name)
      }
    }
  }
  return errorObject
}
function msg ( name , type , errorNames ) { name = name . charAt ( 0 ) . toUpperCase ( ) + name . slice ( 1 ) let errorObject = { } errorObject [ ` ${ type } ` ] = messages [ ` ${ type } ` ] . replace ( '<name>' , name ) if ( errorNames && errorNames . length > 0 ) { for ( const errorName of errorNames ) { let errorCode = ` ${ type } ${ errorName } ` if ( errorName == 'required' ) errorCode = 'any.required' if ( ! messages [ errorCode ] ) { console . log ( ` ${ errorCode } ` ) errorObject [ errorCode ] = ` ${ errorCode } ` } else { errorObject [ errorCode ] = messages [ errorCode ] . replace ( '<name>' , name ) } } } return errorObject }
msg - Create a list of error Codes and custom messages for Joi schemas,
 customized based on the parameters
msg - Create a list of error Codes and custom messages for Joi schemas customized based on the parameters
/** Capitalize the input field name for nicer presentation */ /** Add '*.base' error message */ /** loop through message array, if any */ /** Add message to the object list, overwriting the the name */