Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!