Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const email = req.body.email;
- const password = req.body.password;
- const query = UserModel.findOne({ email });
- query.exec()
- .then((existingUser) => {
- if (existingUser) {
- logger.info('user found');
- return res.status(422).send({ error: 'Email in use' });
- }
- const user = new UserModel({
- email,
- password
- });
- return user.save()
- .then(() => {
- res.send({ error: false });
- })
- ;
- })
- .catch((err) => {
- logger.error(err);
- if (err.name === 'ValidationError') {
- return res.status(422).send(
- { error: `You must provide: ${Object.keys(err.errors).join(', ')}` }
- );
- }
- return res.send({ error: true });
- })
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement