generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from Arquisoft/sonia
cambiado lo de la query
- Loading branch information
Showing
2 changed files
with
22 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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) { | ||
|