Skip to content

Commit

Permalink
Merge pull request #283 from Arquisoft/sonia
Browse files Browse the repository at this point in the history
cambiado lo de la query
  • Loading branch information
bidof authored Apr 25, 2024
2 parents 0c9022a + a281005 commit 1c6c9e5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 16 additions & 0 deletions users/authservice/actualizarUsuario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const mongoose = require('mongoose');

const User = mongoose.model('User');

class ActualizarUsuario{

async updateUserDaily(datos){
return await User.findOneAndUpdate(
{ username: datos.user, $or: [{ diaria: null }, { diaria: { $exists: true } }] },
{ $set: { diaria: datos.fecha } }, // Establecer el valor de 'diaria' a la fecha proporcionada
{ new: true, upsert: true, strict: false } // Para devolver el documento actualizado y permitir campos no definidos en el esquema
);
}
}

module.exports = ActualizarUsuario;
11 changes: 6 additions & 5 deletions users/authservice/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const User = require('./auth-model')

const ActualizarUser = require("./actualizarUsuario");
const actualizarUser = new ActualizarUser();

const app = express();
const port = 8002;

Expand Down Expand Up @@ -76,11 +79,9 @@ app.post('/updateUserDaily', async (req, res) => {
try {

Check failure

Code scanning / SonarCloud

NoSQL operations should not be vulnerable to injection attacks High

Change this code to not construct database queries directly from user-controlled data. See more on SonarCloud
console.log("Entra en el auth service del update")
if((req.body.user != null && req.body.fecha != null) || (req.body.user != undefined && req.body.fecha != undefined)){
var user = await User.findOneAndUpdate(
{ username:req.body.user, $or: [{ diaria: null }, { diaria: { $exists: true } }] },
{ $set: { diaria: req.body.fecha } }, // Establecer el valor de 'diaria' a la fecha proporcionada
{ new: true, upsert: true, strict: false } // Para devolver el documento actualizado y permitir campos no definidos en el esquema
);
let datos = {userData : user, fecha: fecha};

var user = await actualizarUser.updateUserDaily(datos);
}
res.json({ user: user});
} catch (error) {
Expand Down

0 comments on commit 1c6c9e5

Please sign in to comment.