Files
probo/packages/n8n-node/nodes/Probo/actions/vendor/createService.operation.ts
Sacha Al Himdani 88572b07da Add service to vendor on n8n
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
2025-12-15 11:15:55 +01:00

88 lines
1.8 KiB
TypeScript

import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { proboApiRequest } from '../../GenericFunctions';
export const description: INodeProperties[] = [
{
displayName: 'Vendor ID',
name: 'vendorId',
type: 'string',
displayOptions: {
show: {
resource: ['vendor'],
operation: ['createService'],
},
},
default: '',
description: 'The ID of the vendor',
required: true,
},
{
displayName: 'Name',
name: 'name',
type: 'string',
displayOptions: {
show: {
resource: ['vendor'],
operation: ['createService'],
},
},
default: '',
description: 'The name of the vendor service',
required: true,
},
{
displayName: 'Description',
name: 'description',
type: 'string',
typeOptions: {
rows: 4,
},
displayOptions: {
show: {
resource: ['vendor'],
operation: ['createService'],
},
},
default: '',
description: 'The description of the vendor service',
},
];
export async function execute(
this: IExecuteFunctions,
itemIndex: number,
): Promise<INodeExecutionData> {
const vendorId = this.getNodeParameter('vendorId', itemIndex) as string;
const name = this.getNodeParameter('name', itemIndex) as string;
const description = this.getNodeParameter('description', itemIndex, '') as string;
const query = `
mutation CreateVendorService($input: CreateVendorServiceInput!) {
createVendorService(input: $input) {
vendorServiceEdge {
node {
id
name
description
createdAt
updatedAt
}
}
}
}
`;
const input: Record<string, unknown> = {
vendorId,
name,
};
if (description) input.description = description;
const responseData = await proboApiRequest.call(this, query, { input });
return {
json: responseData,
pairedItem: { item: itemIndex },
};
}