import { GraphQLObjectType, GraphQLString, GraphQLInputObjectType, GraphQLBoolean, GraphQLInt, GraphQLList, GraphQLFloat, GraphQLNonNull, } from 'graphql'; import { authorized } from '../auth'; import { omit } from 'lodash'; const roleDescription = { id: 'An id of the role', name: 'Name of the role', code: 'Code of the role', }; import { createRole, updateRole, } from './roleRepository'; import { IRole, } from '../model/role'; interface InputRole { input: IRole; } export const roleType = new GraphQLObjectType({ name: 'RoleType', description: 'Role Type', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLInt), description: roleDescription.id, }, name: { type: new GraphQLNonNull(GraphQLString), description: roleDescription.name, }, code: { type: new GraphQLNonNull(GraphQLString), description: roleDescription.code, }, }), }); export const createRoleInputType = new GraphQLInputObjectType({ name: 'CreateRoleInputType', description: 'Use this object to create new role', fields: () => ({ name: { type: new GraphQLNonNull(GraphQLString), description: roleDescription.name, }, code: { type: new GraphQLNonNull(GraphQLString), description: roleDescription.code, }, }), }); export const updateRoleInputType = new GraphQLInputObjectType({ name: 'UpdateRoleInputType', description: 'Use this object to update role', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLInt), description: roleDescription.id, }, name: { type: GraphQLString, description: roleDescription.name, }, }), }); export default { createRole: { description: 'Creates new role', type: roleType, args: { input: { type: new GraphQLNonNull(createRoleInputType) }, }, resolve: authorized( ['AM'], (_: any, inputUser: InputRole) => { const input = inputUser.input; return createRole(input); }, ), }, updateRole: { description: 'Updates a role', type: roleType, args: { input: { type: new GraphQLNonNull(updateRoleInputType) }, }, resolve: authorized( ['AM'], (_: any, inputUser: InputRole) => { const input = inputUser.input; return updateRole(input); }, ), }, };