Open fabiomattes2016 opened 4 years ago
const mongoose = require('mongoose'); const { Schema } = mongoose const UUIDv4 = require('uuid').v4(); const bcrypt = require('bcryptjs'); const UserSchema = new Schema({ _id: { type: String, default: UUIDv4, }, name: String, dateOfBirth: Date, docType: String, docNumber: String, email: String, status: Number, password: String, address: { street: String, complement: String, country: String, state: String, city: String, zipcode: String, number: String, }, }, { timestamps: {} }); UserSchema.pre('save', async function(next) { const hash = await bcrypt.hash(this.password, 10); this.password = hash; next(); }); module.exports = new mongoose.model('User', UserSchema);