Add organization operations

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-12-02 15:01:09 +01:00
parent 6ba68ee830
commit ba4c229ef1
8 changed files with 447 additions and 0 deletions

View File

@@ -92,6 +92,11 @@ export class Probo implements INodeType {
value: 'measure',
description: 'Manage measures',
},
{
name: 'Organization',
value: 'organization',
description: 'Manage organizations',
},
],
default: 'execute',
},

View File

@@ -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<string, ResourceModule> = {
execute: execute as ResourceModule,
framework: framework as ResourceModule,
measure: measure as ResourceModule,
organization: organization as ResourceModule,
};
export function getAllResourceOperations(): INodeProperties[] {

View File

@@ -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<INodeExecutionData> {
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 },
};
}

View File

@@ -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<INodeExecutionData> {
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 },
};
}

View File

@@ -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<INodeExecutionData> {
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 },
};
}

View File

@@ -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<INodeExecutionData> {
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 },
};
}

View File

@@ -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 };

View File

@@ -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<INodeExecutionData> {
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<string, string> = { 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 },
};
}