- Bitcoin

- Circuito non aggiungere se già esiste
This commit is contained in:
Surya Paolo
2024-02-23 22:12:36 +01:00
parent 204a625e06
commit 3191312372
2 changed files with 17 additions and 6 deletions

View File

@@ -2057,15 +2057,20 @@ UserSchema.statics.addCircuitToUser = async function (idapp, usernameOrig, circu
} else { } else {
// prima di aggiungerlo controlla se esiste già !
let update = { let update = {
$push: { $addToSet: { // Utilizziamo $addToSet invece di $push per garantire che l'elemento venga aggiunto solo se non esiste già
'profile.mycircuits': { 'profile.mycircuits': {
circuitname, $each: [{
date: new Date(), circuitname,
}, date: new Date(),
}, }],
}
}
}; };
ris = await User.updateOne({ idapp, username: usernameOrig }, update);
ris = await User.updateOne({ idapp, username: usernameOrig, 'profile.mycircuits': { $not: { $elemMatch: { circuitname } } } }, update);
if (confido) { if (confido) {
// Elimina la richiesta: // Elimina la richiesta:

View File

@@ -173,5 +173,11 @@ module.exports = {
"label" : "Euro", "label" : "Euro",
"__v" : 0 "__v" : 0
}, },
{
"_id" : ObjectID("51bc482667de9a1f64b254ff"),
"idapp" : "13",
"label" : "Bitcoin",
"__v" : 0
},
] ]
} }