Commit project
This commit is contained in:
parent
28471965a0
commit
3ac017a5ad
1030 changed files with 94062 additions and 0 deletions
55
models/merchant.js
Normal file
55
models/merchant.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
'use strict';
|
||||
|
||||
var mongoose = require('mongoose');
|
||||
var bcrypt = require('bcrypt');
|
||||
var Schema = mongoose.Schema;
|
||||
|
||||
var MerchantSchema = new Schema({
|
||||
name: String,
|
||||
password: String,
|
||||
merchant_email: {
|
||||
type: String,
|
||||
index: { unique: true }
|
||||
},
|
||||
merchant_name: String,
|
||||
language: String,
|
||||
street: String,
|
||||
street_2: String,
|
||||
city: String,
|
||||
province: String,
|
||||
postal_code: String,
|
||||
country: String,
|
||||
telephone: String,
|
||||
cellular: String,
|
||||
telephone_other: String,
|
||||
number: Number
|
||||
}, {timestamps: true});
|
||||
|
||||
MerchantSchema.methods.comparePassword = function comparePassword(password, callback) {
|
||||
bcrypt.compare(password, this.password, callback);
|
||||
};
|
||||
|
||||
MerchantSchema.pre('save', function saveHook(next) {
|
||||
let user = this;
|
||||
|
||||
// proceed only if password is modified or the user is new
|
||||
if (!user.isModified('password')) {
|
||||
return next();
|
||||
}
|
||||
|
||||
return bcrypt.genSalt((saltError, salt) => {
|
||||
if (saltError) {
|
||||
return next(saltError);
|
||||
}
|
||||
return bcrypt.hash(user.password, salt, (hashError, hash) => {
|
||||
if (hashError) {
|
||||
return next(hashError);
|
||||
}
|
||||
// Replace password string with hash value
|
||||
user.password = hash;
|
||||
return next();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Merchant', MerchantSchema);
|
Loading…
Add table
Add a link
Reference in a new issue