UNPKG

eyght-models

Version:

Models for eyght

50 lines (44 loc) 1.89 kB
let mongoose = require('mongoose'), Bcrypt = require('bcrypt-nodejs'); mongoose.Promise = global.Promise; let arCustSchema = new mongoose.Schema({ eygCustID: { name: {type: 'String', required: true}, num: {type: 'Number', required: true} }, //Generated from some portion of their name with a number . This will allow us to give the same id to customers whom we can't determine for sure if they are the same person or not. custName: {type: 'String'}, busName: {type: 'String'}, langID: {type: mongoose.Schema.Types.ObjectId, ref: 'genLang'}, clientInfo: [{ clientID: {type: mongoose.Schema.Types.ObjectId, ref: 'eygClient'}, clientCustID: {type: 'String'}, clientCustType: {type: mongoose.Schema.Types.ObjectId, ref: 'arCustType'}, clientCustDomIntlCatID: {type: mongoose.Schema.Types.ObjectId, ref: 'genDomIntlCat'} }], custClientID: {type: mongoose.Schema.Types.ObjectId, ref: 'eygClient'}, roles: [{type: mongoose.Schema.Types.ObjectId, ref: 'eygRole'}], password: {type: 'String'}, active: {type: 'Boolean', required: true}, inactDt: {type: 'Date'}, //store all dates in utc inactRsnID: {type: mongoose.Schema.Types.ObjectId, ref: 'genInactRsn'} }, {timestamps: true}); arCustSchema.methods.generateHash = (password) => { return new Promise((resolve, reject) => { Bcrypt.genSalt(10, function (err, salt) { if (err) return reject(err); Bcrypt.hash(password, salt, null, (err, hash) => { if (err) return reject(false); else return resolve(hash); }); }); }); }; arCustSchema.methods.validatePassword = (password) => { return new Promise((resolve, reject) => { Bcrypt.compare(password, this.password, function (err, isMatch) { if (err) return reject(err); else return resolve(isMatch); }); }); }; module.exports = mongoose.model('arCust', arCustSchema, 'arCust');