Browse Source

fix: drop userKeys on user delete

pull/1609/head
NGPixel 4 years ago
parent
commit
fcd37afdb0
2 changed files with 16 additions and 1 deletions
  1. 2
      server/graph/resolvers/user.js
  2. 15
      server/models/users.js

2
server/graph/resolvers/user.js

@ -45,7 +45,7 @@ module.exports = {
if (args.id <= 2) { if (args.id <= 2) {
throw new WIKI.Error.UserDeleteProtected() throw new WIKI.Error.UserDeleteProtected()
} }
await WIKI.models.users.query().deleteById(args.id)
await WIKI.models.users.deleteUser(args.id)
return { return {
responseResult: graphHelper.generateSuccess('User deleted successfully') responseResult: graphHelper.generateSuccess('User deleted successfully')
} }

15
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) * Register a new user (client-side registration)
* *

Loading…
Cancel
Save