add in backend function deleteUser()

This commit is contained in:
ogerly 2022-02-18 14:46:09 +01:00 committed by Ulf Gebhardt
parent 09258eb57a
commit fed3562e4d
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
3 changed files with 21 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import gql from 'graphql-tag'
export const deleteUser = gql`
mutation ($userId: Int!) {
mutation ($userId: Float!) {
deleteUser(userId: $userId)
}
`

View File

@ -26,4 +26,5 @@ export enum RIGHTS {
DELETE_PENDING_CREATION = 'DELETE_PENDING_CREATION',
CONFIRM_PENDING_CREATION = 'CONFIRM_PENDING_CREATION',
SEND_ACTIVATION_EMAIL = 'SEND_ACTIVATION_EMAIL',
DELETE_USER = 'DELETE_USER',
}

View File

@ -95,6 +95,25 @@ export class AdminResolver {
}
}
@Authorized([RIGHTS.DELETE_USER])
@Mutation(() => Boolean)
async deleteUser(@Arg('userId') userId: number, @Ctx() context: any): Promise<boolean> {
const user = await User.findOne({ id: userId })
// user exists ?
if (!user) {
throw new Error(`Could not find user with userId: ${userId}`)
}
// moderator user disabled own account?
const userRepository = getCustomRepository(UserRepository)
const moderatorUser = await userRepository.findByPubkeyHex(context.pubKey)
if (moderatorUser.id === userId) {
throw new Error('Moderator can not delete his own account!')
}
// soft-delete user
await user.softRemove()
return true
}
@Authorized([RIGHTS.CREATE_PENDING_CREATION])
@Mutation(() => [Number])
async createPendingCreation(