feat(Airtable Node): Add support for returnFieldsByFieldId parameter

This commit is contained in:
HBS999 2025-02-17 21:18:34 +03:00
parent c90d0d9161
commit 142ba47ff7
11 changed files with 58 additions and 9 deletions

View file

@ -54,6 +54,7 @@ describe('Test AirtableV2, create operation', () => {
], ],
}, },
options: { options: {
returnFieldsByFieldId: true,
typecast: true, typecast: true,
ignoreFields: 'spam', ignoreFields: 'spam',
}, },
@ -89,6 +90,7 @@ describe('Test AirtableV2, create operation', () => {
foo: 'foo 1', foo: 'foo 1',
bar: 'bar 1', bar: 'bar 1',
}, },
returnFieldsByFieldId: true,
typecast: true, typecast: true,
}); });
expect(transport.apiRequest).toHaveBeenCalledWith('POST', 'appYoLbase/tblltable', { expect(transport.apiRequest).toHaveBeenCalledWith('POST', 'appYoLbase/tblltable', {
@ -96,6 +98,7 @@ describe('Test AirtableV2, create operation', () => {
foo: 'foo 2', foo: 'foo 2',
bar: 'bar 2', bar: 'bar 2',
}, },
returnFieldsByFieldId: true,
typecast: true, typecast: true,
}); });
}); });
@ -151,6 +154,7 @@ describe('Test AirtableV2, create operation', () => {
foo: 'foo 1', foo: 'foo 1',
bar: 'bar 1', bar: 'bar 1',
}, },
returnFieldsByFieldId: false,
typecast: false, typecast: false,
}); });
}); });

View file

@ -42,7 +42,12 @@ describe('Test AirtableV2, create operation', () => {
); );
expect(transport.apiRequest).toHaveBeenCalledTimes(1); expect(transport.apiRequest).toHaveBeenCalledTimes(1);
expect(transport.apiRequest).toHaveBeenCalledWith('GET', 'appYoLbase/tblltable/recXXX'); expect(transport.apiRequest).toHaveBeenCalledWith(
'GET',
'appYoLbase/tblltable/recXXX',
{},
{ returnFieldsByFieldId: false },
);
expect(responce).toEqual([ expect(responce).toEqual([
{ {

View file

@ -90,6 +90,7 @@ describe('Test AirtableV2, search operation', () => {
{ {
fields: ['foo', 'bar'], fields: ['foo', 'bar'],
filterByFormula: 'foo', filterByFormula: 'foo',
returnFieldsByFieldId: false,
sort: [{ direction: 'desc', field: 'bar' }], sort: [{ direction: 'desc', field: 'bar' }],
view: 'viwView', view: 'viwView',
}, },
@ -132,7 +133,12 @@ describe('Test AirtableV2, search operation', () => {
'GET', 'GET',
'appYoLbase/tblltable', 'appYoLbase/tblltable',
{}, {},
{ fields: ['foo', 'bar'], filterByFormula: 'foo', maxRecords: 1 }, {
fields: ['foo', 'bar'],
filterByFormula: 'foo',
maxRecords: 1,
returnFieldsByFieldId: false,
},
); );
expect(result).toHaveLength(1); expect(result).toHaveLength(1);

View file

@ -67,7 +67,7 @@ describe('Test AirtableV2, update operation', () => {
expect(transport.batchUpdate).toHaveBeenCalledWith( expect(transport.batchUpdate).toHaveBeenCalledWith(
'appYoLbase/tblltable', 'appYoLbase/tblltable',
{ typecast: false }, { returnFieldsByFieldId: false, typecast: false },
[{ fields: { bar: 'bar 1', foo: 'foo 1' }, id: 'recXXX' }], [{ fields: { bar: 'bar 1', foo: 'foo 1' }, id: 'recXXX' }],
); );
}); });
@ -101,7 +101,7 @@ describe('Test AirtableV2, update operation', () => {
expect(transport.batchUpdate).toHaveBeenCalledWith( expect(transport.batchUpdate).toHaveBeenCalledWith(
'appYoLbase/tblltable', 'appYoLbase/tblltable',
{ typecast: false }, { returnFieldsByFieldId: false, typecast: false },
[{ fields: { bar: 'bar 1', foo: 'foo 1', id: 'recXXX' }, id: 'recXXX' }], [{ fields: { bar: 'bar 1', foo: 'foo 1', id: 'recXXX' }, id: 'recXXX' }],
); );
}); });

View file

@ -202,6 +202,14 @@ export const insertUpdateOptions: INodeProperties[] = [
}, },
}, },
}, },
{
displayName: 'Return Fields By Field ID',
name: 'returnFieldsByFieldId',
type: 'boolean',
default: false,
description:
'Whether to return fields keyed by field ID instead of field name in the response',
},
], ],
}, },
]; ];

View file

@ -65,6 +65,7 @@ export async function execute(
const options = this.getNodeParameter('options', i, {}); const options = this.getNodeParameter('options', i, {});
const body: IDataObject = { const body: IDataObject = {
returnFieldsByFieldId: options.returnFieldsByFieldId ? true : false,
typecast: options.typecast ? true : false, typecast: options.typecast ? true : false,
}; };

View file

@ -44,6 +44,14 @@ const properties: INodeProperties[] = [
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-multi-options // eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-dynamic-multi-options
description: "The fields of type 'attachment' that should be downloaded", description: "The fields of type 'attachment' that should be downloaded",
}, },
{
displayName: 'Return Fields By Field ID',
name: 'returnFieldsByFieldId',
type: 'boolean',
default: false,
description:
'Whether to return fields keyed by field ID instead of field name in the response',
},
], ],
}, },
]; ];
@ -69,10 +77,13 @@ export async function execute(
let id; let id;
try { try {
id = this.getNodeParameter('id', i) as string; id = this.getNodeParameter('id', i) as string;
const options = this.getNodeParameter('options', i, {});
const responseData = await apiRequest.call(this, 'GET', `${base}/${table}/${id}`); const query: IDataObject = {
returnFieldsByFieldId: options.returnFieldsByFieldId ? true : false,
};
const options = this.getNodeParameter('options', 0, {}); const responseData = await apiRequest.call(this, 'GET', `${base}/${table}/${id}`, {}, query);
if (options.downloadFields) { if (options.downloadFields) {
const itemWithAttachments = await downloadRecordAttachments.call( const itemWithAttachments = await downloadRecordAttachments.call(

View file

@ -80,6 +80,14 @@ const properties: INodeProperties[] = [
description: 'The fields you want to include in the output', description: 'The fields you want to include in the output',
}, },
viewRLC, viewRLC,
{
displayName: 'Return Fields By Field ID',
name: 'returnFieldsByFieldId',
type: 'boolean',
default: false,
description:
'Whether to return fields keyed by field ID instead of field name in the response',
},
], ],
}, },
{ {
@ -169,7 +177,9 @@ export async function execute(
const filterByFormula = this.getNodeParameter('filterByFormula', i) as string; const filterByFormula = this.getNodeParameter('filterByFormula', i) as string;
const body: IDataObject = {}; const body: IDataObject = {};
const qs: IDataObject = {}; const qs: IDataObject = {
returnFieldsByFieldId: options.returnFieldsByFieldId ? true : false,
};
if (filterByFormula) { if (filterByFormula) {
qs.filterByFormula = filterByFormula; qs.filterByFormula = filterByFormula;

View file

@ -127,7 +127,10 @@ export async function execute(
} }
} }
const body: IDataObject = { typecast: options.typecast ? true : false }; const body: IDataObject = {
returnFieldsByFieldId: options.returnFieldsByFieldId ? true : false,
typecast: options.typecast ? true : false,
};
const responseData = await batchUpdate.call(this, endpoint, body, records); const responseData = await batchUpdate.call(this, endpoint, body, records);

View file

@ -94,6 +94,7 @@ export async function execute(
} }
const body: IDataObject = { const body: IDataObject = {
returnFieldsByFieldId: options.returnFieldsByFieldId ? true : false,
typecast: options.typecast ? true : false, typecast: options.typecast ? true : false,
}; };

View file

@ -101,7 +101,7 @@ export async function getColumns(this: ILoadOptionsFunctions): Promise<ResourceM
const isReadOnly = airtableReadOnlyFields.includes(field.type); const isReadOnly = airtableReadOnlyFields.includes(field.type);
const options = constructOptions(field); const options = constructOptions(field);
fields.push({ fields.push({
id: field.name, id: field.id,
displayName: field.name, displayName: field.name,
required: false, required: false,
defaultMatch: false, defaultMatch: false,