mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 15:47:48 +01:00
when deleting user, delete each todolist with .remove()
This commit is contained in:
@@ -22,15 +22,10 @@ UserSchema.plugin(passportLocalMongoose);
|
||||
UserSchema.plugin(uniqueValidator);
|
||||
|
||||
UserSchema.pre('remove', async function () {
|
||||
await this.model('TodoList')
|
||||
const lists = await this.model('TodoList')
|
||||
.find({ user: this._id })
|
||||
.remove()
|
||||
.exec();
|
||||
|
||||
await this.model('Todo')
|
||||
.find({ user: this._id })
|
||||
.remove()
|
||||
.exec();
|
||||
await Promise.all(lists.map(list => list.remove()));
|
||||
});
|
||||
|
||||
UserSchema.methods.generateJwt = function () {
|
||||
|
||||
Reference in New Issue
Block a user