feat: delete user with replace target

This commit is contained in:
NGPixel
2020-05-30 16:34:09 -04:00
parent 006dae1221
commit 1f9e5b3fd0
15 changed files with 1703 additions and 749 deletions

View File

@@ -613,9 +613,15 @@ module.exports = class User extends Model {
*
* @param {*} id User ID
*/
static async deleteUser (id) {
static async deleteUser (id, replaceId) {
const usr = await WIKI.models.users.query().findById(id)
if (usr) {
await WIKI.models.assets.query().patch({ authorId: replaceId }).where('authorId', id)
await WIKI.models.comments.query().patch({ authorId: replaceId }).where('authorId', id)
await WIKI.models.pageHistory.query().patch({ authorId: replaceId }).where('authorId', id)
await WIKI.models.pages.query().patch({ authorId: replaceId }).where('authorId', id)
await WIKI.models.pages.query().patch({ creatorId: replaceId }).where('creatorId', id)
await WIKI.models.userKeys.query().delete().where('userId', id)
await WIKI.models.users.query().deleteById(id)
} else {