Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

56
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos