mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
use Context interface in admin resolver
This commit is contained in:
parent
4d09123b0e
commit
9a390c11db
@ -1,6 +1,4 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
import { Context } from '@/server/context'
|
||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
||||||
|
|
||||||
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql'
|
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql'
|
||||||
import {
|
import {
|
||||||
getCustomRepository,
|
getCustomRepository,
|
||||||
@ -137,7 +135,7 @@ export class AdminResolver {
|
|||||||
@Mutation(() => Date, { nullable: true })
|
@Mutation(() => Date, { nullable: true })
|
||||||
async deleteUser(
|
async deleteUser(
|
||||||
@Arg('userId', () => Int) userId: number,
|
@Arg('userId', () => Int) userId: number,
|
||||||
@Ctx() context: any,
|
@Ctx() context: Context,
|
||||||
): Promise<Date | null> {
|
): Promise<Date | null> {
|
||||||
const user = await dbUser.findOne({ id: userId })
|
const user = await dbUser.findOne({ id: userId })
|
||||||
// user exists ?
|
// user exists ?
|
||||||
@ -146,7 +144,7 @@ export class AdminResolver {
|
|||||||
}
|
}
|
||||||
// moderator user disabled own account?
|
// moderator user disabled own account?
|
||||||
const moderatorUser = context.user
|
const moderatorUser = context.user
|
||||||
if (moderatorUser.id === userId) {
|
if (moderatorUser && moderatorUser.id === userId) {
|
||||||
throw new Error('Moderator can not delete his own account!')
|
throw new Error('Moderator can not delete his own account!')
|
||||||
}
|
}
|
||||||
// soft-delete user
|
// soft-delete user
|
||||||
@ -309,11 +307,11 @@ export class AdminResolver {
|
|||||||
@Mutation(() => Boolean)
|
@Mutation(() => Boolean)
|
||||||
async confirmPendingCreation(
|
async confirmPendingCreation(
|
||||||
@Arg('id', () => Int) id: number,
|
@Arg('id', () => Int) id: number,
|
||||||
@Ctx() context: any,
|
@Ctx() context: Context,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const pendingCreation = await AdminPendingCreation.findOneOrFail(id)
|
const pendingCreation = await AdminPendingCreation.findOneOrFail(id)
|
||||||
const moderatorUser = context.user
|
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')
|
throw new Error('Moderator can not confirm own pending creation')
|
||||||
|
|
||||||
const user = await dbUser.findOneOrFail({ id: pendingCreation.userId }, { withDeleted: true })
|
const user = await dbUser.findOneOrFail({ id: pendingCreation.userId }, { withDeleted: true })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user