From d373510f2108633ee5c39ad0052ce2089720ced6 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 30 Aug 2024 23:09:48 +0530 Subject: [PATCH] added user choice to join or create group --- helpers/validateUserChoice.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 helpers/validateUserChoice.js 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 }; +};