Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

55
Views
Constructor makes an object of the first parameter with all the results

I'm trying to register an user and I use a constructor class for it, but when I put the parameters in the constructor and make the query, it takes the first parameter that I passed to the constructor and puts all the information as if it were an object of that parameter. Like this:

enter image description here

And when I try to put a parameter to be able to use it like this this.username = username, I meet with this

enter image description here

Here's my code:

class User{
    constructor(user){
        this.username = user.username
        this.email = user.email
        this.birthday = user.birthday
        this.picture = user.picture
        this.password = user.password
    }
}

//////

async signUp(req,res){
        const newUser = new User(req.body)
        console.log(newUser)
        const result = await newUser.save()
        console.log(result)
        return res.redirect("/")
}

////

router.post("/signup", authcontroller.signUp)
7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

If the problem is as you've described then your problem must originate in the req.body. You are probably sending the data in a wrong format so try printing out the contents just to be certain.

If it is, simply adjust it to the proper structure.

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.