120 lines
3.4 KiB
TypeScript
120 lines
3.4 KiB
TypeScript
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
|
|
//
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
// copyright notice and this permission notice appear in all copies.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
|
import { proboApiRequest } from '../../GenericFunctions';
|
|
|
|
export const description: INodeProperties[] = [
|
|
{
|
|
displayName: 'ThirdParty Contact ID',
|
|
name: 'thirdPartyContactId',
|
|
type: 'string',
|
|
displayOptions: {
|
|
show: {
|
|
resource: ['thirdParty'],
|
|
operation: ['updateContact'],
|
|
},
|
|
},
|
|
default: '',
|
|
description: 'The ID of the thirdParty contact to update',
|
|
required: true,
|
|
},
|
|
{
|
|
displayName: 'Additional Fields',
|
|
name: 'additionalFields',
|
|
type: 'collection',
|
|
placeholder: 'Add Field',
|
|
default: {},
|
|
displayOptions: {
|
|
show: {
|
|
resource: ['thirdParty'],
|
|
operation: ['updateContact'],
|
|
},
|
|
},
|
|
options: [
|
|
{
|
|
displayName: 'Email',
|
|
name: 'email',
|
|
type: 'string',
|
|
placeholder: 'name@email.com',
|
|
default: '',
|
|
description: 'The email address of the contact',
|
|
},
|
|
{
|
|
displayName: 'Full Name',
|
|
name: 'fullName',
|
|
type: 'string',
|
|
default: '',
|
|
description: 'The full name of the contact',
|
|
},
|
|
{
|
|
displayName: 'Phone',
|
|
name: 'phone',
|
|
type: 'string',
|
|
default: '',
|
|
description: 'The phone number of the contact',
|
|
},
|
|
{
|
|
displayName: 'Role',
|
|
name: 'role',
|
|
type: 'string',
|
|
default: '',
|
|
description: 'The role of the contact',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
export async function execute(
|
|
this: IExecuteFunctions,
|
|
itemIndex: number,
|
|
): Promise<INodeExecutionData> {
|
|
const thirdPartyContactId = this.getNodeParameter('thirdPartyContactId', itemIndex) as string;
|
|
const additionalFields = this.getNodeParameter('additionalFields', itemIndex, {}) as {
|
|
fullName?: string;
|
|
email?: string;
|
|
phone?: string;
|
|
role?: string;
|
|
};
|
|
|
|
const query = `
|
|
mutation UpdateThirdPartyContact($input: UpdateThirdPartyContactInput!) {
|
|
updateThirdPartyContact(input: $input) {
|
|
thirdPartyContact {
|
|
id
|
|
fullName
|
|
email
|
|
phone
|
|
role
|
|
createdAt
|
|
updatedAt
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
const input: Record<string, unknown> = { id: thirdPartyContactId };
|
|
if (additionalFields.fullName !== undefined) input.fullName = additionalFields.fullName === '' ? null : additionalFields.fullName;
|
|
if (additionalFields.email !== undefined) input.email = additionalFields.email === '' ? null : additionalFields.email;
|
|
if (additionalFields.phone !== undefined) input.phone = additionalFields.phone === '' ? null : additionalFields.phone;
|
|
if (additionalFields.role !== undefined) input.role = additionalFields.role === '' ? null : additionalFields.role;
|
|
|
|
const responseData = await proboApiRequest.call(this, query, { input });
|
|
|
|
return {
|
|
json: responseData,
|
|
pairedItem: { item: itemIndex },
|
|
};
|
|
}
|