Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return User.find({ username })
- .count()
- .then(count => {
- if (count > 0) {
- return Promise.reject({
- code: 422,
- reason: 'ValidationError',
- message: 'Username already taken',
- location: 'username'
- });
- }
- return User.hashPassword(password);
- })
- .then((digest) => {
- const newUser = { username, password: digest, currentCash, careerCash, manualClicks, clickValue, assets, upgrades, seenMessage };
- return User.create(newUser);
- })
- .then(result => {
- return res.status(201).location(`/api/users/${result.username}`).json(result);
- })
- .catch(err => {
- if (err.code === 11000) {
- err = new Error('The username already exists');
- err.status = 400;
- }
- next(err);
- });
Add Comment
Please, Sign In to add comment