UNPKG

iworks-core-api

Version:

iwroks server api module

498 lines (469 loc) 12.7 kB
import { GraphQLObjectType, GraphQLString, GraphQLInputObjectType, GraphQLBoolean, GraphQLInt, GraphQLList, GraphQLFloat, GraphQLNonNull, } from 'graphql'; import { ICreateProject, IDeleteProject, IUpdateProject, } from '../model/renovationProject'; import { createRenovationProject, deleteRenovationProject, updateRenovationProject, } from './renovationProjectRepository'; interface ICreateProjectInput { input: ICreateProject; } interface IUpdateProjectInput { input: IUpdateProject; } interface IDeleteProjectInput { input: IDeleteProject; } const statePropertyDescription = { id: 'State property id', layoutCode: 'A layout code (a developer code or an external system code)', address: 'An address', propertyType: 'Type of the property ("office" or "flat")', residentialComplexId: 'Residential complex id', }; const statePropertyPropsInputType = new GraphQLInputObjectType({ name: 'StatePropertyPropsInputType', description: 'State property additional props type', fields: () => ({ roomNumber: { type: GraphQLInt, description: 'Number of rooms', }, area: { type: GraphQLFloat, description: 'Area of flat', }, }), }); const createStatePropertyInputType = new GraphQLInputObjectType({ name: 'CreateStatePropertyInputType', description: 'Create state property input type', fields: () => ({ layoutCode: { type: GraphQLString, description: statePropertyDescription.layoutCode, }, address: { type: new GraphQLNonNull(GraphQLString), description: statePropertyDescription.address, }, propertyType: { type: new GraphQLNonNull(GraphQLString), description: statePropertyDescription.propertyType, }, residentialComplexId: { type: GraphQLString, description: statePropertyDescription.residentialComplexId, }, props: { type: statePropertyPropsInputType, description: 'Additional property props', }, }), }); const editStatePropertyInputType = new GraphQLInputObjectType({ name: 'StatePropertyInputType', description: 'State property input type', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLString), description: statePropertyDescription.id, }, layoutCode: { type: GraphQLString, description: statePropertyDescription.layoutCode, }, address: { type: GraphQLString, description: statePropertyDescription.address, }, propertyType: { type: GraphQLString, description: statePropertyDescription.propertyType, }, residentialComplexId: { type: GraphQLString, description: statePropertyDescription.residentialComplexId, }, props: { type: statePropertyPropsInputType, description: 'Additional properties', }, }), }); const customerDescription = { id: 'Customer unique id', firstName: 'Customer first name', middleName: 'Customer middle name', lastName: 'Customer last name', name: 'If legal entity it\'s name of company', individual: 'True if this is individual', phone: 'Customer phone number', email: 'Customer email address', }; const createCustomerInputType = new GraphQLInputObjectType({ name: 'CreateCustomerInputType', description: 'Create customer input type', fields: () => ({ firstName: { type: new GraphQLNonNull(GraphQLString), description: customerDescription.firstName, }, middleName: { type: GraphQLString, description: customerDescription.middleName, }, lastName: { type: new GraphQLNonNull(GraphQLString), description: customerDescription.lastName, }, name: { type: GraphQLString, description: customerDescription.name, }, individual: { type: new GraphQLNonNull(GraphQLBoolean), description: customerDescription.individual, }, phone: { type: new GraphQLNonNull(GraphQLString), description: customerDescription.phone, }, email: { type: new GraphQLNonNull(GraphQLString), description: customerDescription.email, }, }), }); const editCustomerInputType = new GraphQLInputObjectType({ name: 'EditCustomerInputType', description: 'Edit customer type', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLString), description: customerDescription.id, }, firstName: { type: GraphQLString, description: customerDescription.firstName, }, middleName: { type: GraphQLString, description: customerDescription.middleName, }, lastName: { type: GraphQLString, description: customerDescription.lastName, }, name: { type: GraphQLString, description: customerDescription.name, }, individual: { type: GraphQLBoolean, description: customerDescription.individual, }, phone: { type: GraphQLString, description: customerDescription.phone, }, email: { type: GraphQLString, description: customerDescription.email, }, }), }); const jobDescription = { id: 'Job template id (GUID)', vol: 'Job volume', providerLinked: 'Provider linked', }; const jobInputType = new GraphQLInputObjectType({ name: 'JobInputType', description: 'Job parameters', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLString), description: jobDescription.id, }, vol: { type: new GraphQLNonNull(GraphQLFloat), description: jobDescription.vol, }, providerLinked: { type: new GraphQLNonNull(GraphQLBoolean), description: jobDescription.providerLinked, }, }), }); const projectDescription = { id: 'Project id', renovationProjectTplId: 'Project template Id (use 99103d13-baa2-4500-97eb-c54522d689bd as a default)', ownerId: 'Project owner id (typically the office coordinator)', managerId: 'Project manager id', price: 'Price', stateProperty: 'State property selected for the renovation', customer: 'New customer data', customerId: 'Exist customer\'s id', jobs: 'Project jobs list', props: 'Additional project properties', agreementNum: 'Agreement number', agreementDate: 'Agreement date', bimProjectRef: 'BIM project reference in the cloud (i.e. A360)', techDocRef: 'Technical specification reference', discount: 'Customer discount for this project', created: 'Creation date', updated: 'Last update date', fees: 'List of financial coefficient', }; const feesDescription = { agentFee: 'Agents fee, % of base price', pmFee: 'Project managers fee, % of base price', tnFee: 'Tech controls fee, % of base price', workerFee: 'Workers fee, % of base price', jobPriceMultiplicator: 'The coefficient of change in base price', materialsDiscount: 'Discount on materials', }; const projectFeesInputType = new GraphQLInputObjectType({ name: 'ProjectFeesInputType', description: 'Fees of employee', fields: () => ({ agentFee: { type: GraphQLFloat, description: feesDescription.agentFee, }, pmFee: { type: GraphQLFloat, description: feesDescription.pmFee, }, tnFee: { type: GraphQLFloat, description: feesDescription.tnFee, }, workerFee: { type: GraphQLFloat, description: feesDescription.workerFee, }, jobPriceMultiplicator: { type: GraphQLFloat, description: feesDescription.jobPriceMultiplicator, }, materialsDiscount: { type: GraphQLFloat, description: feesDescription.materialsDiscount, }, }), }); const projectPropsInputType = new GraphQLInputObjectType({ name: 'ProjectPropsInputType', description: 'Create new project', fields: () => ({ agreementNum: { type: GraphQLString, description: projectDescription.agreementNum, }, agreementDate: { type: GraphQLString, description: projectDescription.agreementDate, }, bimProjectRef: { type: GraphQLString, description: projectDescription.bimProjectRef, }, techDocRef: { type: GraphQLString, description: projectDescription.techDocRef, }, fees: { type: projectFeesInputType, description: projectDescription.fees, }, }), }); const updateProjectInputType = new GraphQLInputObjectType({ name: 'UpdateProjectInputType', description: 'Updates project', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLString), description: projectDescription.id, }, ownerId: { type: GraphQLString, description: projectDescription.ownerId, }, managerId: { type: GraphQLString, description: projectDescription.managerId, }, stateProperty: { type: editStatePropertyInputType, description: projectDescription.stateProperty, }, customer: { type: editCustomerInputType, description: projectDescription.customer, }, props: { type: projectPropsInputType, description: projectDescription.props, }, }), }); const createProjectInputType = new GraphQLInputObjectType({ name: 'CreateProjectInputType', description: 'Creates new project', fields: () => ({ renovationProjectTplId: { type: new GraphQLNonNull(GraphQLString), description: projectDescription.renovationProjectTplId, }, ownerId: { type: GraphQLString, description: projectDescription.ownerId, }, managerId: { type: GraphQLString, description: projectDescription.managerId, }, stateProperty: { type: createStatePropertyInputType, description: projectDescription.stateProperty, }, customer: { type: createCustomerInputType, description: projectDescription.customer, }, customerId: { type: GraphQLString, description: projectDescription.customerId, }, jobs: { type: new GraphQLList(jobInputType), description: projectDescription.jobs, }, props: { type: projectPropsInputType, description: projectDescription.props, }, }), }); const deleteProjectInputType = new GraphQLInputObjectType({ name: 'DeleteProjectInputType', description: 'Delete Project Input Type', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLString), description: projectDescription.id, }, }), }); const projectFees = new GraphQLObjectType({ name: 'ProjectFees', description: 'Renovation project fees', fields: () => ({ agentFee: { type: GraphQLFloat, }, pmFee: { type: GraphQLFloat, }, tnFee: { type: GraphQLFloat, }, workerFee: { type: GraphQLFloat, }, jobPriceMultiplicator: { type: GraphQLFloat, }, materialsDiscount: { type: GraphQLFloat, }, }), }); const projectProps = new GraphQLObjectType({ name: 'ProjectProps', description: 'Renovation project properties', fields: () => ({ agreementNum: { type: GraphQLString, }, agreementDate: { type: GraphQLString, }, bimProjectRef: { type: GraphQLString, }, techDocRef: { type: GraphQLString, }, fees: { type: projectFees, }, }), }); const projectType = new GraphQLObjectType({ // no idea why before was just id name: 'ProjectType', description: 'Renovation project type', fields: () => ({ id: { type: new GraphQLNonNull(GraphQLString), description: projectDescription.id, }, props: { type: new GraphQLNonNull(projectProps), description: projectDescription.props, }, updated: { type: new GraphQLNonNull(GraphQLString), description: projectDescription.updated, }, }), }); export default { createRenovationProject: { description: 'Creates a new renovation project', type: projectType, args: { input: { type: new GraphQLNonNull(createProjectInputType) }, }, resolve: (_: any, { input }: ICreateProjectInput) => { return createRenovationProject(input); }, }, updateRenovationProject: { description: 'Updates renovation project', type: projectType, args: { input: { type: new GraphQLNonNull(updateProjectInputType) }, }, resolve: (_: any, { input }: IUpdateProjectInput) => { return updateRenovationProject(input); }, }, deleteRenovationProject: { description: 'Delete renovation project', type: GraphQLBoolean, args: { input: { type: new GraphQLNonNull(deleteProjectInputType) }, }, resolve: (_: any, { input }: IDeleteProjectInput) => { return deleteRenovationProject(input); }, }, };