• Empleos
  • Sobre nosotros
  • Empleos
    • Inicio
    • Empleos
    • Cursos y retos
  • Empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

131
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)
over 3 years 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.

over 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda