mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
0bea158832
refs #12537
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
const path = require('path');
|
|
const dbBackup = require('../data/db/backup');
|
|
const models = require('../models');
|
|
|
|
async function destroyUser(frameOptions) {
|
|
const backupPath = await dbBackup.backup();
|
|
const parsedFileName = path.parse(backupPath);
|
|
const filename = `${parsedFileName.name}${parsedFileName.ext}`;
|
|
|
|
return models.Base.transaction((t) => {
|
|
frameOptions.transacting = t;
|
|
|
|
return models.Post.destroyByAuthor(frameOptions)
|
|
.then(() => {
|
|
return models.ApiKey.destroy({
|
|
...frameOptions,
|
|
require: true,
|
|
destroyBy: {
|
|
user_id: frameOptions.id
|
|
}
|
|
}).catch((err) => {
|
|
if (err instanceof models.ApiKey.NotFoundError) {
|
|
return; //Do nothing here as it's ok
|
|
}
|
|
throw err;
|
|
});
|
|
})
|
|
.then(() => {
|
|
return models.User.destroy(Object.assign({status: 'all'}, frameOptions));
|
|
})
|
|
.then(() => filename);
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
destroyUser
|
|
};
|