mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Refactored destroyUser method to async/await
refs https://github.com/TryGhost/Toolbox/issues/268 - Before doing a functional change to this method wanted to make sure it's more readable to keep better track of changes
This commit is contained in:
parent
39f4abbbcd
commit
f5937c6f65
1 changed files with 20 additions and 20 deletions
|
@ -73,28 +73,28 @@ class Users {
|
|||
const parsedFileName = path.parse(backupPath);
|
||||
const filename = `${parsedFileName.name}${parsedFileName.ext}`;
|
||||
|
||||
return this.models.Base.transaction((t) => {
|
||||
return this.models.Base.transaction(async (t) => {
|
||||
frameOptions.transacting = t;
|
||||
|
||||
return this.models.Post.destroyByAuthor(frameOptions)
|
||||
.then(() => {
|
||||
return this.models.ApiKey.destroy({
|
||||
...frameOptions,
|
||||
require: true,
|
||||
destroyBy: {
|
||||
user_id: frameOptions.id
|
||||
}
|
||||
}).catch((err) => {
|
||||
if (err instanceof this.models.ApiKey.NotFoundError) {
|
||||
return; //Do nothing here as it's ok
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return this.models.User.destroy(Object.assign({status: 'all'}, frameOptions));
|
||||
})
|
||||
.then(() => filename);
|
||||
await this.models.Post.destroyByAuthor(frameOptions);
|
||||
|
||||
try {
|
||||
await this.models.ApiKey.destroy({
|
||||
...frameOptions,
|
||||
require: true,
|
||||
destroyBy: {
|
||||
user_id: frameOptions.id
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
if (!(err instanceof this.models.ApiKey.NotFoundError)) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
await this.models.User.destroy(Object.assign({status: 'all'}, frameOptions));
|
||||
|
||||
return filename;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue