import { GraphQLObjectType, GraphQLString, GraphQLInputObjectType, GraphQLBoolean, GraphQLInt, GraphQLNonNull, } from 'graphql'; import { IJobInstanceSelector, IJobInstanceAdd } from '../model/jobInstance'; import { authorized } from '../auth'; import { deleteJobInstance, addJobInstance } from './jobInstanceRepository'; interface IJobInstanceSelectorInput { input: IJobInstanceSelector; } interface IJobInstanceAddInput { input: IJobInstanceAdd; } const jobInstanceDescription = { id: 'Job instance id', projectStageId: 'Id of current project stage', jobTplId: 'Id of jobTpl', vol: 'Volume of work in job instance', providerLinked: 'If true then volume is not editable and should be linked to the external provider', }; const jobInstanceSelectorInputType = new GraphQLInputObjectType({ name: 'JobInstanceSelectorInputType', description: 'Job Instance Selector Input Type', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLInt), description: jobInstanceDescription.id, }, }), }); const jobInstanceAddType = new GraphQLObjectType({ name:'JobInstanceAddType', description: 'Job Instance Add Type', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLInt), description: jobInstanceDescription.id, }, }), }); const jobInstanceAddInputType = new GraphQLInputObjectType({ name:'JobInstanceAddInputType', description: 'Job Instance Add Input Type', fields: () => ({ projectStageId: { type: new GraphQLNonNull(GraphQLInt), description: jobInstanceDescription.projectStageId, }, jobTplId: { type: new GraphQLNonNull(GraphQLString), description: jobInstanceDescription.jobTplId, }, vol: { type: new GraphQLNonNull(GraphQLInt), description: jobInstanceDescription.vol, }, providerLinked: { type: GraphQLBoolean, description: jobInstanceDescription.providerLinked, }, }), }); export default { deleteJobInstance: { description: 'Project coordinator can delete job instance of project stage', type: GraphQLBoolean, args: { input: { type: new GraphQLNonNull(jobInstanceSelectorInputType) }, }, resolve: authorized( ['AM', 'CD'], (_: any, { input }: IJobInstanceSelectorInput) => { return deleteJobInstance(input); }, ), }, addJobInstance: { description: 'Add job instance to project stage', type: jobInstanceAddType, args: { input: { type: new GraphQLNonNull(jobInstanceAddInputType) }, }, resolve: authorized( ['AM', 'CD'], (_: any, { input }: IJobInstanceAddInput) => { return addJobInstance(input); }), }, };