106 lines
2.0 KiB
TypeScript
106 lines
2.0 KiB
TypeScript
import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
|
import { proboApiRequest } from '../../GenericFunctions';
|
|
|
|
export const description: INodeProperties[] = [
|
|
{
|
|
displayName: 'Datum ID',
|
|
name: 'datumId',
|
|
type: 'string',
|
|
displayOptions: {
|
|
show: {
|
|
resource: ['datum'],
|
|
operation: ['get'],
|
|
},
|
|
},
|
|
default: '',
|
|
description: 'The ID of the datum',
|
|
required: true,
|
|
},
|
|
{
|
|
displayName: 'Options',
|
|
name: 'options',
|
|
type: 'collection',
|
|
placeholder: 'Add Option',
|
|
default: {},
|
|
displayOptions: {
|
|
show: {
|
|
resource: ['datum'],
|
|
operation: ['get'],
|
|
},
|
|
},
|
|
options: [
|
|
{
|
|
displayName: 'Include Owner',
|
|
name: 'includeOwner',
|
|
type: 'boolean',
|
|
default: false,
|
|
description: 'Whether to include owner details in the response',
|
|
},
|
|
{
|
|
displayName: 'Include Vendors',
|
|
name: 'includeVendors',
|
|
type: 'boolean',
|
|
default: false,
|
|
description: 'Whether to include vendors in the response',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
export async function execute(
|
|
this: IExecuteFunctions,
|
|
itemIndex: number,
|
|
): Promise<INodeExecutionData> {
|
|
const datumId = this.getNodeParameter('datumId', itemIndex) as string;
|
|
const options = this.getNodeParameter('options', itemIndex, {}) as {
|
|
includeOwner?: boolean;
|
|
includeVendors?: boolean;
|
|
};
|
|
|
|
const ownerFragment = options.includeOwner
|
|
? `owner {
|
|
id
|
|
fullName
|
|
primaryEmailAddress
|
|
}`
|
|
: '';
|
|
|
|
const vendorsFragment = options.includeVendors
|
|
? `vendors(first: 100) {
|
|
edges {
|
|
node {
|
|
id
|
|
name
|
|
}
|
|
}
|
|
}`
|
|
: '';
|
|
|
|
const query = `
|
|
query GetDatum($datumId: ID!) {
|
|
node(id: $datumId) {
|
|
... on Datum {
|
|
id
|
|
name
|
|
dataClassification
|
|
${ownerFragment}
|
|
${vendorsFragment}
|
|
createdAt
|
|
updatedAt
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
const variables = {
|
|
datumId,
|
|
};
|
|
|
|
const responseData = await proboApiRequest.call(this, query, variables);
|
|
|
|
return {
|
|
json: responseData,
|
|
pairedItem: { item: itemIndex },
|
|
};
|
|
}
|