Created
June 10, 2021 16:01
-
-
Save harryWonder/ce496f1ee9773a75df3d514e77622a3b to your computer and use it in GitHub Desktop.
LD NodeJS & Nginx Base Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is the base validator class. All other validator classes extends this class thus sharing resuable methods. | |
* | |
* @author Ilori Stephen A <stephenilori458@gmail.com> | |
* @returns {Object} | |
* @name Validator | |
* @param {Null} | |
* | |
*/ | |
const AppConfigs = require('../config/App'); | |
const _Validator = require('validator'); | |
class Validator { | |
/* Calling The Galaxy For Help! */ | |
async validateEmail(Payload, Model) { | |
const Response = { status: false, errors: {} }; | |
try { | |
if (!_Validator.isEmail(Payload.email)) { | |
Response.status = true; | |
Response.errors.email = 'Please, enter a valid email address'; | |
} | |
const checkEmail = await Model.findOne({ email: Payload.email }).lean(); | |
if (checkEmail) { | |
Response.status = true; | |
Response.errors.email = 'Sorry, this email address is not available.'; | |
} | |
return Response; | |
} catch (e) { | |
Response.status = true; | |
Response.errors.server = 'Sorry, an unexpected error occurred and your request could not be processed.'; | |
return Response; | |
} | |
} | |
fetchAppConfigs() { | |
return AppConfigs(); | |
} | |
} | |
module.exports = Validator; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment