define Int as type for args of Ids

This commit is contained in:
Moriz Wahl 2022-03-17 13:03:41 +01:00
parent 6124e0764f
commit 4c396d7581
2 changed files with 12 additions and 7 deletions

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx } from 'type-graphql'
import { Resolver, Query, Arg, Args, Authorized, Mutation, Ctx, Int } from 'type-graphql'
import {
getCustomRepository,
IsNull,
@ -122,7 +122,10 @@ export class AdminResolver {
@Authorized([RIGHTS.DELETE_USER])
@Mutation(() => Date, { nullable: true })
async deleteUser(@Arg('userId') userId: number, @Ctx() context: any): Promise<Date | null> {
async deleteUser(
@Arg('userId', () => Int) userId: number,
@Ctx() context: any,
): Promise<Date | null> {
const user = await User.findOne({ id: userId })
// user exists ?
if (!user) {
@ -142,7 +145,7 @@ export class AdminResolver {
@Authorized([RIGHTS.UNDELETE_USER])
@Mutation(() => Date, { nullable: true })
async unDeleteUser(@Arg('userId') userId: number): Promise<Date | null> {
async unDeleteUser(@Arg('userId', () => Int) userId: number): Promise<Date | null> {
const user = await User.findOne({ id: userId }, { withDeleted: true })
// user exists ?
if (!user) {
@ -284,7 +287,7 @@ export class AdminResolver {
@Authorized([RIGHTS.DELETE_PENDING_CREATION])
@Mutation(() => Boolean)
async deletePendingCreation(@Arg('id') id: number): Promise<boolean> {
async deletePendingCreation(@Arg('id', () => Int) id: number): Promise<boolean> {
const entity = await AdminPendingCreation.findOneOrFail(id)
const res = await AdminPendingCreation.delete(entity)
return !!res
@ -292,7 +295,10 @@ export class AdminResolver {
@Authorized([RIGHTS.CONFIRM_PENDING_CREATION])
@Mutation(() => Boolean)
async confirmPendingCreation(@Arg('id') id: number, @Ctx() context: any): Promise<boolean> {
async confirmPendingCreation(
@Arg('id', () => Int) id: number,
@Ctx() context: any,
): Promise<boolean> {
const pendingCreation = await AdminPendingCreation.findOneOrFail(id)
const userRepository = getCustomRepository(UserRepository)
const moderatorUser = await userRepository.findByPubkeyHex(context.pubKey)

View File

@ -39,7 +39,6 @@ const apolloLogPlugin = ApolloLogPlugin({
},
})
const plugins =
process.env.NODE_ENV === 'development' ? [setHeadersPlugin] : [setHeadersPlugin, apolloLogPlugin]
const plugins = process.env.NODE_ENV === 'development' ? [setHeadersPlugin] : [setHeadersPlugin] // , apolloLogPlugin
export default plugins