diff --git a/helpers/validateUserChoice.js b/helpers/validateUserChoice.js new file mode 100644 index 0000000..44f9d3d --- /dev/null +++ b/helpers/validateUserChoice.js @@ -0,0 +1,19 @@ +module.exports.validateUsersChoice = (choice, options) => { + if (!choice) { + return { + isValid: false, + message: "User Choice is mandatory", + }; + } + + if (!options.includes(choice)) { + return { + isValid: false, + message: `Invalid choice, Please choose one of the options: ${options.join( + ", " + )}`, + }; + } + + return { isValid: true }; +};