Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

189
Vistas
How to create a PUT controller in nodejs

I’m trying to create a PUT request using Axios, what I want to do is update a user’s information once a button is pressed,

Button code:

<button id="evaluator-button" class="button-submit" onclick="ft_evaluate()">Submit</button>
function ft_evaluate () {
    console.log(sessionStorage.getItem('Counter') + ' of ' + sessionStorage.getItem('Max'));
    let evaluationPoints = document.getElementById('evaluator-input').value;
    let userLogin = document.getElementById('match-login').innerHTML;
    let actualPoints = document.getElementById('match-points').innerHTML;

    if (evaluationPoints == 0 || !userLogin) { 
        return ;
    }
    else {
        evaluationPoints = evaluationPoints * 10 / 100;
        actualPoints = parseFloat(actualPoints.replace(/[^0-9]/g, '')) / 100;
        let newPoints = actualPoints + evaluationPoints;
        newPoints = newPoints.toFixed(2);

        console.log(newPoints, actualPoints, evaluationPoints, userLogin);

        fetch('http://localhost:3005/script/data', {
            method: 'PUT',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                login: userLogin,
                points: newPoints
            })
        });

    }
}

And this is the controller code:

const scriptPutData = (req, res) => {
    authUser.find({}, async (err, data) => {
        if (err) {
            console.error(clc.red(`${err}`));
        }
        else {
            if (data.find(dbUser => dbUser.login === req.session.login)) {
                // What i should do inside this block to update the info?
            }
            else {
                res.redirect('/login');
                return;
            }
        }
    });
}

The info of the user have this format:

 [
      {
         "login": "ezidane-",
         "name": "Enzo Zidane",
         "points": 0.45,
         "nacionality": "French",
         "bool_malaga": "1",
         "bool_andalucia": "1",
         "city": "Vélez-Málaga",
         "laboral_status": "Desempleado/a",
         "image": "https://xxxxxxxxxx.jpg",
         "pmonth": "february",
         "pyear": "2022",
         "motivational": "https://api.xxxxxx.jpg"
      }
   ]

I just wanna update the points for each user [login] who press the button.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda