tanmya
tanmya

Reputation: 103

Graphql error newUser is not defined while using mongoose

I am new to GraphQL. I was trying to create a signup function where a user is saved in mongo only when the invite code matches with mycode variable.

User.find({mycode:invitationcode
    }).then(code=>{
      if(code){
        console.log("yes")
        const newUser=new User({
        fullName,
        email,
        username,
        password,
        invitationcode,
        mycode
      }).save();
      }else{
        console.log(
          "no"
        )
      }
    })

VSCode shows this when hovered-'newUser' is declared but its value is never read.

please help

Upvotes: 0

Views: 73

Answers (1)

abearxiong
abearxiong

Reputation: 11

User.find({mycode:invitationcode
    }).then(async code=>{
      if(code){
        console.log("yes")
        const newUser= await new User({
        fullName,
        email,
        username,
        password,
        invitationcode,
        mycode
      }).save();
      }else{
        console.log(
          "no"
        )
      }
    })

Upvotes: 1

Related Questions