- Bitcoin
- Circuito non aggiungere se già esiste
This commit is contained in:
@@ -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:
|
||||||
|
|||||||
@@ -173,5 +173,11 @@ module.exports = {
|
|||||||
"label" : "Euro",
|
"label" : "Euro",
|
||||||
"__v" : 0
|
"__v" : 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"_id" : ObjectID("51bc482667de9a1f64b254ff"),
|
||||||
|
"idapp" : "13",
|
||||||
|
"label" : "Bitcoin",
|
||||||
|
"__v" : 0
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user