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) 742 B
const City = require('../../../models/city') const { buildErrObject } = require('../../../middleware/utils') /** * Checks if a city already exists excluding itself * @param {string} id - id of item * @param {string} name - name of item */ const cityExistsExcludingItself = (id = '', name = '') => { return new Promise((resolve, reject) => { City.findOne( { name, _id: { $ne: id } }, (err, item) => { if (err) { return reject(buildErrObject(422, err.message)) } if (item) { return reject(buildErrObject(422, 'CITY_ALREADY_EXISTS')) } resolve(false) } ) }) } module.exports = { cityExistsExcludingItself }