如何返回用户已经存在并成功创建用户?

时间:2019-01-19 18:45:00

标签: sequelize.js

这是我的代码如何返回User Exist而不是Exist。谢谢oyu

exports.create=(req, res)=>{
let registration=req.body.email;
User.findOrCreate({
    where: {
        email: registration
    }

}).spread((user,created)=>{
    console.log(user.get({
        plain: true
    }))
})
console.log(created)
 };

1 个答案:

答案 0 :(得分:0)

exports.create=(req, res)=>{
let registration=req.body.email;
User.findOrCreate({
   where: {
      email: registration
 }

}).spread((user,created)=>{
   if (created){
      res.send({ message: "user Created Successfully" });
   }
   else {
     res.send({ message: "user Already exists" });
   }
})
   console.log(created)
};

有关更多详细信息,请阅读此文档link