mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-04-14 11:46:23 +00:00
Make sure no userhistory exists before initializing it (#15415)
This commit is contained in:
parent
ded71b46c5
commit
c0d5566417
1 changed files with 7 additions and 3 deletions
|
|
@ -365,9 +365,13 @@ schema.pre('save', true, async function preSaveUser (next, done) {
|
|||
}
|
||||
if (!this.flags.initializedUserHistory) {
|
||||
this.flags.initializedUserHistory = true;
|
||||
const history = UserHistory();
|
||||
history.userId = this._id;
|
||||
await history.save();
|
||||
// Ensure that it does not try to create a new history if it already exists
|
||||
const existingHistory = await UserHistory.findOne({ userId: this._id });
|
||||
if (!existingHistory) {
|
||||
const history = UserHistory();
|
||||
history.userId = this._id;
|
||||
await history.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue