How to Calculate Nodejs Points with mysql and sequelize of several Users

Asked

Viewed 45 times

0

Calculo Onde puxo informções do banco || calculo acontece de forma correta pore o envio para o banco atravez do update funciona não corretamente.

Basically it would pull through a loop pass through all users to pick up the points already existing and add with what he scored thus forming a cumulative total.

total = total + pts

console.log RES:[1]: https://i.stack.Imgur.com/rivNh.png

var total = 0

Usuario.findAll().then(usCal =>{
    
    usCal.forEach(calculoT =>{
        total = calculoT.pontos
        t = total
        
        console.log("id: ", calculoT.id,"pontos acumulados: ", total)
        
    })
})
// fazer mais duas colunas no mysql
app.get("/calc", (req, res)=>{
    Palpite.findAll().then(calc =>{
        res.render("calc/index", {calc: calc, log: 1})
        var idUser = 0
        var p1 = 0
        var p2 = 0
        var p3 = 0
        var p4 = 0
        var p5 = 0

        var rp1 = 16
        var rp2 = 16
        var rp3 = 16
        var rp4 = 16
        var rp5 = 16


        calc.forEach(calcu => {
            
            idUser = calcu.idUsuario
            p1 = calcu.p1
            p2 = calcu.p2
            p3 = calcu.p3
            p4 = calcu.p4
            p5 = calcu.p5
            pontosDeEtapa = 0
            

            if(p1 == rp1){
                pontosDeEtapa = pontosDeEtapa+10
            }
            
             if(p2 == rp2){
                pontosDeEtapa = pontosDeEtapa+10
            }
            
             if(p3 == rp3){
                pontosDeEtapa = pontosDeEtapa+10
            }
            
             if(p4 == rp4){
                pontosDeEtapa = pontosDeEtapa+10
            }
            
             if(p5 == rp5){
                pontosDeEtapa = pontosDeEtapa+10
            }
            console.log('total de pontos por etapa: ',pontosDeEtapa, 'do id: ',idUser)
            var cont = 1
            cont++
            if(cont > idUser){
                
            }
            Palpite.update({idCorrida: pontosDeEtapa},{
                
                where: {
                    idUsuario: idUser
                }
            })
            
            
            console.log('total de pontos enviados: ', total, ' para ', idUser)
            var to = pontosDeEtapa+total
            console.log(to)
            
            
            Usuario.update({pontos: to},{
                
                where: {
                    id: idUser
                }
            })
            console.log(idUser, p1, p2, p3, p4, p5, pontosDeEtapa)
        });
    })
})


  • What is the expected output? Already checked in the database the value that was saved?

  • the expected output and the sum of points at the end

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.