use getUser helper to get moderator form context

This commit is contained in:
Moriz Wahl 2022-04-12 19:04:29 +02:00
parent f752d8d045
commit de6421201d

View File

@ -1,4 +1,4 @@
import { Context } from '@/server/context'
import { Context, getUser } from '@/server/context'
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql'
import {
getCustomRepository,
@ -143,8 +143,8 @@ export class AdminResolver {
throw new Error(`Could not find user with userId: ${userId}`)
}
// moderator user disabled own account?
const moderatorUser = context.user
if (moderatorUser && moderatorUser.id === userId) {
const moderatorUser = getUser(context)
if (moderatorUser.id === userId) {
throw new Error('Moderator can not delete his own account!')
}
// soft-delete user
@ -310,8 +310,8 @@ export class AdminResolver {
@Ctx() context: Context,
): Promise<boolean> {
const pendingCreation = await AdminPendingCreation.findOneOrFail(id)
const moderatorUser = context.user
if (moderatorUser && moderatorUser.id === pendingCreation.userId)
const moderatorUser = getUser(context)
if (moderatorUser.id === pendingCreation.userId)
throw new Error('Moderator can not confirm own pending creation')
const user = await dbUser.findOneOrFail({ id: pendingCreation.userId }, { withDeleted: true })