diff --git a/packages/n8n-node/nodes/Probo/Probo.node.ts b/packages/n8n-node/nodes/Probo/Probo.node.ts index 40c23c3ed..928e90525 100644 --- a/packages/n8n-node/nodes/Probo/Probo.node.ts +++ b/packages/n8n-node/nodes/Probo/Probo.node.ts @@ -92,6 +92,11 @@ export class Probo implements INodeType { value: 'measure', description: 'Manage measures', }, + { + name: 'Organization', + value: 'organization', + description: 'Manage organizations', + }, ], default: 'execute', }, diff --git a/packages/n8n-node/nodes/Probo/actions/index.ts b/packages/n8n-node/nodes/Probo/actions/index.ts index caf7c0106..1dffceec7 100644 --- a/packages/n8n-node/nodes/Probo/actions/index.ts +++ b/packages/n8n-node/nodes/Probo/actions/index.ts @@ -5,6 +5,7 @@ import * as datum from './datum'; import * as execute from './execute'; import * as framework from './framework'; import * as measure from './measure'; +import * as organization from './organization'; export interface ResourceModule { description: INodeProperties[]; @@ -23,6 +24,7 @@ export const resources: Record = { execute: execute as ResourceModule, framework: framework as ResourceModule, measure: measure as ResourceModule, + organization: organization as ResourceModule, }; export function getAllResourceOperations(): INodeProperties[] { diff --git a/packages/n8n-node/nodes/Probo/actions/organization/create.operation.ts b/packages/n8n-node/nodes/Probo/actions/organization/create.operation.ts new file mode 100644 index 000000000..c4d792e02 --- /dev/null +++ b/packages/n8n-node/nodes/Probo/actions/organization/create.operation.ts @@ -0,0 +1,61 @@ +import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; +import { proboApiRequest } from '../../GenericFunctions'; + +export const description: INodeProperties[] = [ + { + displayName: 'Name', + name: 'name', + type: 'string', + displayOptions: { + show: { + resource: ['organization'], + operation: ['create'], + }, + }, + default: '', + description: 'The name of the organization', + required: true, + }, +]; + +export async function execute( + this: IExecuteFunctions, + itemIndex: number, +): Promise { + const name = this.getNodeParameter('name', itemIndex) as string; + + const query = ` + mutation CreateOrganization($input: CreateOrganizationInput!) { + createOrganization(input: $input) { + organizationEdge { + node { + id + name + description + websiteUrl + email + headquarterAddress + logoUrl + horizontalLogoUrl + createdAt + updatedAt + } + } + } + } + `; + + const variables = { + input: { + name, + }, + }; + + const responseData = await proboApiRequest.call(this, query, variables); + + return { + json: responseData, + pairedItem: { item: itemIndex }, + }; +} + diff --git a/packages/n8n-node/nodes/Probo/actions/organization/delete.operation.ts b/packages/n8n-node/nodes/Probo/actions/organization/delete.operation.ts new file mode 100644 index 000000000..e2be52fd1 --- /dev/null +++ b/packages/n8n-node/nodes/Probo/actions/organization/delete.operation.ts @@ -0,0 +1,42 @@ +import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; +import { proboApiRequest } from '../../GenericFunctions'; + +export const description: INodeProperties[] = [ + { + displayName: 'Organization ID', + name: 'organizationId', + type: 'string', + displayOptions: { + show: { + resource: ['organization'], + operation: ['delete'], + }, + }, + default: '', + description: 'The ID of the organization to delete', + required: true, + }, +]; + +export async function execute( + this: IExecuteFunctions, + itemIndex: number, +): Promise { + const organizationId = this.getNodeParameter('organizationId', itemIndex) as string; + + const query = ` + mutation DeleteOrganization($input: DeleteOrganizationInput!) { + deleteOrganization(input: $input) { + deletedOrganizationId + } + } + `; + + const responseData = await proboApiRequest.call(this, query, { input: { organizationId } }); + + return { + json: responseData, + pairedItem: { item: itemIndex }, + }; +} + diff --git a/packages/n8n-node/nodes/Probo/actions/organization/get.operation.ts b/packages/n8n-node/nodes/Probo/actions/organization/get.operation.ts new file mode 100644 index 000000000..6c3205c25 --- /dev/null +++ b/packages/n8n-node/nodes/Probo/actions/organization/get.operation.ts @@ -0,0 +1,57 @@ +import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; +import { proboApiRequest } from '../../GenericFunctions'; + +export const description: INodeProperties[] = [ + { + displayName: 'Organization ID', + name: 'organizationId', + type: 'string', + displayOptions: { + show: { + resource: ['organization'], + operation: ['get'], + }, + }, + default: '', + description: 'The ID of the organization', + required: true, + }, +]; + +export async function execute( + this: IExecuteFunctions, + itemIndex: number, +): Promise { + const organizationId = this.getNodeParameter('organizationId', itemIndex) as string; + + const query = ` + query GetOrganization($organizationId: ID!) { + node(id: $organizationId) { + ... on Organization { + id + name + description + websiteUrl + email + headquarterAddress + logoUrl + horizontalLogoUrl + createdAt + updatedAt + } + } + } + `; + + const variables = { + organizationId, + }; + + const responseData = await proboApiRequest.call(this, query, variables); + + return { + json: responseData, + pairedItem: { item: itemIndex }, + }; +} + diff --git a/packages/n8n-node/nodes/Probo/actions/organization/getAll.operation.ts b/packages/n8n-node/nodes/Probo/actions/organization/getAll.operation.ts new file mode 100644 index 000000000..b4247f89c --- /dev/null +++ b/packages/n8n-node/nodes/Probo/actions/organization/getAll.operation.ts @@ -0,0 +1,89 @@ +import type { INodeProperties, IExecuteFunctions, INodeExecutionData, IDataObject } from 'n8n-workflow'; +import { proboApiRequestAllItems } from '../../GenericFunctions'; + +export const description: INodeProperties[] = [ + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: ['organization'], + operation: ['getAll'], + }, + }, + default: false, + description: 'Whether to return all results or only up to a given limit', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: ['organization'], + operation: ['getAll'], + returnAll: [false], + }, + }, + typeOptions: { + minValue: 1, + }, + default: 50, + description: 'Max number of results to return', + }, +]; + +export async function execute( + this: IExecuteFunctions, + itemIndex: number, +): Promise { + const returnAll = this.getNodeParameter('returnAll', itemIndex) as boolean; + const limit = this.getNodeParameter('limit', itemIndex, 50) as number; + + const query = ` + query GetOrganizations($first: Int, $after: CursorKey) { + viewer { + organizations(first: $first, after: $after) { + edges { + node { + id + name + description + websiteUrl + email + headquarterAddress + logoUrl + horizontalLogoUrl + createdAt + updatedAt + } + } + pageInfo { + hasNextPage + endCursor + } + } + } + } + `; + + const organizations = await proboApiRequestAllItems.call( + this, + query, + {}, + (response) => { + const data = response?.data as IDataObject | undefined; + const viewer = data?.viewer as IDataObject | undefined; + return viewer?.organizations as IDataObject | undefined; + }, + returnAll, + limit, + ); + + return { + json: { organizations }, + pairedItem: { item: itemIndex }, + }; +} + diff --git a/packages/n8n-node/nodes/Probo/actions/organization/index.ts b/packages/n8n-node/nodes/Probo/actions/organization/index.ts new file mode 100644 index 000000000..c64bf0803 --- /dev/null +++ b/packages/n8n-node/nodes/Probo/actions/organization/index.ts @@ -0,0 +1,61 @@ +import type { INodeProperties } from 'n8n-workflow'; +import * as createOp from './create.operation'; +import * as updateOp from './update.operation'; +import * as deleteOp from './delete.operation'; +import * as getOp from './get.operation'; +import * as getAllOp from './getAll.operation'; + +export const description: INodeProperties[] = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + noDataExpression: true, + displayOptions: { + show: { + resource: ['organization'], + }, + }, + options: [ + { + name: 'Create', + value: 'create', + description: 'Create a new organization', + action: 'Create an organization', + }, + { + name: 'Delete', + value: 'delete', + description: 'Delete an organization', + action: 'Delete an organization', + }, + { + name: 'Get', + value: 'get', + description: 'Get an organization', + action: 'Get an organization', + }, + { + name: 'Get Many', + value: 'getAll', + description: 'Get many organizations', + action: 'Get many organizations', + }, + { + name: 'Update', + value: 'update', + description: 'Update an existing organization', + action: 'Update an organization', + }, + ], + default: 'create', + }, + ...createOp.description, + ...updateOp.description, + ...deleteOp.description, + ...getOp.description, + ...getAllOp.description, +]; + +export { createOp as create, updateOp as update, deleteOp as delete, getOp as get, getAllOp as getAll }; + diff --git a/packages/n8n-node/nodes/Probo/actions/organization/update.operation.ts b/packages/n8n-node/nodes/Probo/actions/organization/update.operation.ts new file mode 100644 index 000000000..c75e20220 --- /dev/null +++ b/packages/n8n-node/nodes/Probo/actions/organization/update.operation.ts @@ -0,0 +1,130 @@ +import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow'; +import { proboApiRequest } from '../../GenericFunctions'; + +export const description: INodeProperties[] = [ + { + displayName: 'Organization ID', + name: 'organizationId', + type: 'string', + displayOptions: { + show: { + resource: ['organization'], + operation: ['update'], + }, + }, + default: '', + description: 'The ID of the organization to update', + required: true, + }, + { + displayName: 'Name', + name: 'name', + type: 'string', + displayOptions: { + show: { + resource: ['organization'], + operation: ['update'], + }, + }, + default: '', + description: 'The name of the organization', + }, + { + displayName: 'Description', + name: 'description', + type: 'string', + displayOptions: { + show: { + resource: ['organization'], + operation: ['update'], + }, + }, + default: '', + description: 'The description of the organization', + }, + { + displayName: 'Website URL', + name: 'websiteUrl', + type: 'string', + displayOptions: { + show: { + resource: ['organization'], + operation: ['update'], + }, + }, + default: '', + description: 'The website URL of the organization', + }, + { + displayName: 'Email', + name: 'email', + type: 'string', + displayOptions: { + show: { + resource: ['organization'], + operation: ['update'], + }, + }, + default: '', + description: 'The email address of the organization', + }, + { + displayName: 'Headquarter Address', + name: 'headquarterAddress', + type: 'string', + displayOptions: { + show: { + resource: ['organization'], + operation: ['update'], + }, + }, + default: '', + description: 'The headquarter address of the organization', + }, +]; + +export async function execute( + this: IExecuteFunctions, + itemIndex: number, +): Promise { + const organizationId = this.getNodeParameter('organizationId', itemIndex) as string; + const name = this.getNodeParameter('name', itemIndex, '') as string; + const description = this.getNodeParameter('description', itemIndex, '') as string; + const websiteUrl = this.getNodeParameter('websiteUrl', itemIndex, '') as string; + const email = this.getNodeParameter('email', itemIndex, '') as string; + const headquarterAddress = this.getNodeParameter('headquarterAddress', itemIndex, '') as string; + + const query = ` + mutation UpdateOrganization($input: UpdateOrganizationInput!) { + updateOrganization(input: $input) { + organization { + id + name + description + websiteUrl + email + headquarterAddress + logoUrl + horizontalLogoUrl + createdAt + updatedAt + } + } + } + `; + + const input: Record = { organizationId }; + if (name) input.name = name; + if (description) input.description = description; + if (websiteUrl) input.websiteUrl = websiteUrl; + if (email) input.email = email; + if (headquarterAddress) input.headquarterAddress = headquarterAddress; + + const responseData = await proboApiRequest.call(this, query, { input }); + + return { + json: responseData, + pairedItem: { item: itemIndex }, + }; +} +