use Context interface in admin resolver

This commit is contained in:
Moriz Wahl 2022-04-11 15:57:59 +02:00
parent 4d09123b0e
commit 9a390c11db

View File

@ -1,6 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Context } from '@/server/context'
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql'
import {
getCustomRepository,
@ -137,7 +135,7 @@ export class AdminResolver {
@Mutation(() => Date, { nullable: true })
async deleteUser(
@Arg('userId', () => Int) userId: number,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<Date | null> {
const user = await dbUser.findOne({ id: userId })
// user exists ?
@ -146,7 +144,7 @@ export class AdminResolver {
}
// moderator user disabled own account?
const moderatorUser = context.user
if (moderatorUser.id === userId) {
if (moderatorUser && moderatorUser.id === userId) {
throw new Error('Moderator can not delete his own account!')
}
// soft-delete user
@ -309,11 +307,11 @@ export class AdminResolver {
@Mutation(() => Boolean)
async confirmPendingCreation(
@Arg('id', () => Int) id: number,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<boolean> {
const pendingCreation = await AdminPendingCreation.findOneOrFail(id)
const moderatorUser = context.user
if (moderatorUser.id === pendingCreation.userId)
if (moderatorUser && moderatorUser.id === pendingCreation.userId)
throw new Error('Moderator can not confirm own pending creation')
const user = await dbUser.findOneOrFail({ id: pendingCreation.userId }, { withDeleted: true })