UNPKG

node-express-mongodb-jwt-rest-api-skeleton

Version:

Node.js express.js MongoDB JWT REST API - This is a basic API REST skeleton written on JavaScript using async/await. Great for building a starter web API for your front-end (Android, iOS, Vue, react, angular, or anything that can consume an API)

34 lines (29 loc) 772 B
const User = require('../../models/user') const { buildErrObject } = require('../../middleware/utils') /** * Checks User model if user with an specific email exists but excluding user id * @param {string} id - user id * @param {string} email - user email */ const emailExistsExcludingMyself = (id = '', email = '') => { return new Promise((resolve, reject) => { User.findOne( { email, _id: { $ne: id } }, async (err, item) => { if (err) { return reject(buildErrObject(422, err.message)) } if (item) { return reject(buildErrObject(422, 'EMAIL_ALREADY_EXISTS')) } resolve(false) } ) }) } module.exports = { emailExistsExcludingMyself }