mirror of
https://github.com/linnovate/mean.git
synced 2025-12-08 19:56:03 +00:00
* feat: upgrade to Angular 13 * feat: switch to ESLint since TSLint has been deprecated * feat: upgrade outdated Node.js packages and Node version within the Dockerfile
23 lines
633 B
JavaScript
23 lines
633 B
JavaScript
const bcrypt = require('bcrypt');
|
|
const Joi = require('joi');
|
|
const User = require('../models/user.model');
|
|
|
|
const userSchema = Joi.object({
|
|
fullname: Joi.string().required(),
|
|
email: Joi.string().email(),
|
|
mobileNumber: Joi.string().regex(/^[1-9][0-9]{9}$/),
|
|
password: Joi.string().required(),
|
|
repeatPassword: Joi.string().required().valid(Joi.ref('password')),
|
|
});
|
|
|
|
module.exports = {
|
|
insert,
|
|
};
|
|
|
|
async function insert(user) {
|
|
user = await userSchema.validateAsync(user, { abortEarly: false });
|
|
user.hashedPassword = bcrypt.hashSync(user.password, 10);
|
|
delete user.password;
|
|
return await new User(user).save();
|
|
}
|