Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/',function (req, res, next) {
- var body = req.body;
- if (!body.name || !body.email || !body.password) {
- return res.status(400).send("Missing username or email or password")
- };
- // case #1- if user was registered (socials platform) before -> just add a password;
- User.findOneAndUpdate({
- email: body.email
- }, {
- $set: {password: body.password}
- })
- .then((user) => {
- if (!user) {
- return User.create(body);
- } else {
- return Promise.resolve(user)
- }
- })
- .then((user) => {
- return res.send({ user: user })
- })
- .catch((err) => {
- if (err.name === 'ValidationError') {
- return res.status(400).send(err)
- }
- res.status(500).send(err)
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement