diff --git a/server/graph/resolvers/user.js b/server/graph/resolvers/user.js index 47ce1bc7..865d701e 100644 --- a/server/graph/resolvers/user.js +++ b/server/graph/resolvers/user.js @@ -45,7 +45,7 @@ module.exports = { if (args.id <= 2) { throw new WIKI.Error.UserDeleteProtected() } - await WIKI.models.users.query().deleteById(args.id) + await WIKI.models.users.deleteUser(args.id) return { responseResult: graphHelper.generateSuccess('User deleted successfully') } diff --git a/server/models/users.js b/server/models/users.js index 426efd07..82de4496 100644 --- a/server/models/users.js +++ b/server/models/users.js @@ -596,6 +596,21 @@ module.exports = class User extends Model { } } + /** + * Delete a User + * + * @param {*} id User ID + */ + static async deleteUser (id) { + const usr = await WIKI.models.users.query().findById(id) + if (usr) { + await WIKI.models.userKeys.query().delete().where('userId', id) + await WIKI.models.users.query().deleteById(id) + } else { + throw new WIKI.Error.UserNotFound() + } + } + /** * Register a new user (client-side registration) *