• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

115
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)
about 3 years 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.

about 3 years 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 vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error