Skip to content

Instantly share code, notes, and snippets.

@harryWonder
Created June 10, 2021 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harryWonder/ce496f1ee9773a75df3d514e77622a3b to your computer and use it in GitHub Desktop.
Save harryWonder/ce496f1ee9773a75df3d514e77622a3b to your computer and use it in GitHub Desktop.
LD NodeJS & Nginx Base Validator
/**
* 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