import { ParseUUIDPipe } from '@nestjs/common/pipes' ; import { Args , Context , Mutation , Query , Resolver } from '@nestjs/graphql' ; import { UpdateUserGroupInput , UpdateUserInput , UpdateUserPermissionInput , User , Group , Permission , UserPermissionsVerification , OperationType , } from '../../schema/graphql.schema' ; import UserService from '../service/user.service' ; import ValidationPipe from '../../validation/validation.pipe' ; import * as UserSchema from '../validation/user.validation.schema' ; import { Permissions } from '../permissions.decorator' ; import { PermissionsType } from '../constants/authorization.constants' ; @ Resolver ( 'User' ) export class UserResolver { constructor ( private userService ) { } @ Permissions ( PermissionsType . ViewUser ) @ Query ( ) getUsers ( ) { return this . userService . getAllUsers ( ) ; } @ Permissions ( PermissionsType . ViewUser ) @ Query ( ) getUser ( @ Args ( 'id' , ParseUUIDPipe ) id ) { return this . userService . getUserById ( id ) ; } @ Permissions ( PermissionsType . EditUser ) @ Mutation ( ) async updateUser ( @ Args ( 'id' , ParseUUIDPipe ) id , @ Args ( 'input' , new ValidationPipe ( UserSchema . UpdateUserSchema ) ) userInput ) { return this . userService . updateUser ( id , userInput ) ; } @ Permissions ( PermissionsType . EditUser ) @ Mutation ( ) async updateUserGroups ( @ Args ( 'id' , ParseUUIDPipe ) id , @ Args ( 'input' ) userInput ) { return this . userService . updateUserGroups ( id , userInput ) ; } @ Permissions ( PermissionsType . EditUser ) @ Mutation ( ) async updateUserPermissions ( @ Args ( 'id' , ParseUUIDPipe ) id , @ Args ( 'input' ) userInput ) { return this . userService . updateUserPermissions ( id , userInput ) ; } @ Permissions ( PermissionsType . DeleteUser ) @ Mutation ( ) async deleteUser ( @ Args ( 'id' , ParseUUIDPipe ) id ) { return this . userService . deleteUser ( id ) ; } @ Permissions ( PermissionsType . ViewUser ) @ Query ( ) async verifyUserPermission ( @ Args ( 'params' ) params , @ Context ( 'user' ) user ) { return this . userService . verifyUserPermissions ( user . id , params . permissions , params . operation || OperationType . AND ) ; } @ Permissions ( PermissionsType . ViewUser ) @ Query ( ) async getUserPermissions ( @ Args ( 'id' , ParseUUIDPipe ) id ) { return this . userService . getUserPermissions ( id ) ; } @ Permissions ( PermissionsType . ViewUser ) @ Query ( ) async getUserGroups ( @ Args ( 'id' , ParseUUIDPipe ) id ) { return this . userService . getUserGroups ( id ) ; } }