mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 23:57:49 +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.plugin(uniqueValidator);
|
||||||
|
|
||||||
UserSchema.pre('remove', async function () {
|
UserSchema.pre('remove', async function () {
|
||||||
await this.model('TodoList')
|
const lists = await this.model('TodoList')
|
||||||
.find({ user: this._id })
|
.find({ user: this._id })
|
||||||
.remove()
|
|
||||||
.exec();
|
|
||||||
|
|
||||||
await this.model('Todo')
|
|
||||||
.find({ user: this._id })
|
|
||||||
.remove()
|
|
||||||
.exec();
|
.exec();
|
||||||
|
await Promise.all(lists.map(list => list.remove()));
|
||||||
});
|
});
|
||||||
|
|
||||||
UserSchema.methods.generateJwt = function () {
|
UserSchema.methods.generateJwt = function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user