mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
⚡ Improvements to Quick Base Node
This commit is contained in:
parent
4eed7bb9fb
commit
60be31d410
|
@ -13,13 +13,15 @@ export class QuickBaseApi implements ICredentialType {
|
|||
name: 'hostname',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
required: true,
|
||||
placeholder: 'demo.quickbase.com',
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'User Token',
|
||||
name: 'userToken',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ export const fieldOperations = [
|
|||
description: 'Get all fields',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
default: 'getAll',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
|
|
@ -52,7 +52,7 @@ export const fileFields = [
|
|||
],
|
||||
},
|
||||
},
|
||||
description: 'The table identifier',
|
||||
description: 'The table identifier.',
|
||||
},
|
||||
{
|
||||
displayName: 'Record ID',
|
||||
|
@ -71,7 +71,7 @@ export const fileFields = [
|
|||
],
|
||||
},
|
||||
},
|
||||
description: 'The unique identifier of the record',
|
||||
description: 'The unique identifier of the record.',
|
||||
},
|
||||
{
|
||||
displayName: 'Field ID',
|
||||
|
|
|
@ -17,11 +17,15 @@ export async function quickbaseApiRequest(this: IExecuteFunctions | ILoadOptions
|
|||
|
||||
const credentials = this.getCredentials('quickbaseApi') as IDataObject;
|
||||
|
||||
if (credentials.hostname === '') {
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
if (!credentials.hostname) {
|
||||
throw new Error('Hostname must be defined');
|
||||
}
|
||||
|
||||
if (credentials.userKey === '') {
|
||||
if (!credentials.userToken) {
|
||||
throw new Error('User Token must be defined');
|
||||
}
|
||||
|
||||
|
@ -71,14 +75,14 @@ export async function quickbaseApiRequest(this: IExecuteFunctions | ILoadOptions
|
|||
export async function getFieldsObject(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, tableId: string): any {
|
||||
const fieldsLabelKey: { [key: string]: number } = {};
|
||||
const fieldsIdKey: { [key: number]: string } = {};
|
||||
const data = await quickbaseApiRequest.call(this, 'GET', '/fields', {}, { tableId });
|
||||
const data = await quickbaseApiRequest.call(this, 'GET', '/fields', {}, { tableId });
|
||||
for (const field of data) {
|
||||
fieldsLabelKey[field.label] = field.id;
|
||||
fieldsIdKey[field.id] = field.label;
|
||||
}
|
||||
return { fieldsLabelKey, fieldsIdKey };
|
||||
}
|
||||
|
||||
|
||||
export async function quickbaseApiRequestAllItems(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const returnData: IDataObject[] = [];
|
||||
|
@ -125,7 +129,7 @@ export async function quickbaseApiRequestAllItems(this: IHookFunctions | ILoadOp
|
|||
returnData.push.apply(returnData, responseData);
|
||||
responseData = [];
|
||||
} while (
|
||||
returnData.length < metadata.totalRecords
|
||||
returnData.length < metadata.totalRecords
|
||||
);
|
||||
|
||||
return returnData;
|
||||
|
|
|
@ -42,7 +42,7 @@ export class QuickBase implements INodeType {
|
|||
displayName: 'Quick Base',
|
||||
name: 'quickbase',
|
||||
icon: 'file:quickbase.png',
|
||||
group: [ 'input' ],
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Integrate with the Quick Base RESTful API.',
|
||||
|
@ -50,11 +50,12 @@ export class QuickBase implements INodeType {
|
|||
name: 'Quick Base',
|
||||
color: '#73489d',
|
||||
},
|
||||
inputs: [ 'main' ],
|
||||
outputs: [ 'main' ],
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'quickbaseApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
|
@ -158,8 +159,8 @@ export class QuickBase implements INodeType {
|
|||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
|
||||
responseData = responseData.splice(0, limit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
returnData.push.apply(returnData, responseData);
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +177,7 @@ export class QuickBase implements INodeType {
|
|||
|
||||
const versionNumber = this.getNodeParameter('versionNumber', i) as string;
|
||||
|
||||
responseData = await quickbaseApiRequest.call(this,'DELETE', `/files/${tableId}/${recordId}/${fieldId}/${versionNumber}`);
|
||||
responseData = await quickbaseApiRequest.call(this, 'DELETE', `/files/${tableId}/${recordId}/${fieldId}/${versionNumber}`);
|
||||
|
||||
returnData.push(responseData);
|
||||
}
|
||||
|
@ -210,20 +211,20 @@ export class QuickBase implements INodeType {
|
|||
|
||||
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||
|
||||
responseData = await quickbaseApiRequest.call(this,'GET', `/files/${tableId}/${recordId}/${fieldId}/${versionNumber}`, {}, {}, { json: false, resolveWithFullResponse: true });
|
||||
responseData = await quickbaseApiRequest.call(this, 'GET', `/files/${tableId}/${recordId}/${fieldId}/${versionNumber}`, {}, {}, { json: false, resolveWithFullResponse: true });
|
||||
|
||||
//content-disposition': 'attachment; filename="dog-puppy-on-garden-royalty-free-image-1586966191.jpg"',
|
||||
const contentDisposition = responseData.headers['content-disposition'];
|
||||
|
||||
const data = Buffer.from(responseData.body as string, 'base64');
|
||||
|
||||
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(data as unknown as Buffer, contentDisposition.split('=')[1]);
|
||||
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(data as unknown as Buffer, contentDisposition.split('=')[1]);
|
||||
}
|
||||
|
||||
|
||||
return this.prepareOutputData(items);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (resource === 'record') {
|
||||
if (operation === 'create') {
|
||||
const tableId = this.getNodeParameter('tableId', 0) as string;
|
||||
|
@ -248,7 +249,7 @@ export class QuickBase implements INodeType {
|
|||
record[fieldsLabelKey[key].toString()] = { value: items[i].json[key] };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
data.push(record);
|
||||
}
|
||||
|
||||
|
@ -269,7 +270,7 @@ export class QuickBase implements INodeType {
|
|||
if (simple === true) {
|
||||
const { data: records } = responseData;
|
||||
responseData = [];
|
||||
|
||||
|
||||
for (const record of records) {
|
||||
const data: IDataObject = {};
|
||||
for (const [key, value] of Object.entries(record)) {
|
||||
|
@ -285,7 +286,7 @@ export class QuickBase implements INodeType {
|
|||
returnData.push(responseData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (operation === 'delete') {
|
||||
for (let i = 0; i < length; i++) {
|
||||
const tableId = this.getNodeParameter('tableId', i) as string;
|
||||
|
@ -329,14 +330,14 @@ export class QuickBase implements INodeType {
|
|||
// body.groupBy = group;
|
||||
// delete body.groupByUi;
|
||||
// }
|
||||
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await quickbaseApiRequestAllItems.call(this, 'POST', '/records/query', body, qs);
|
||||
} else {
|
||||
body.options = { top: this.getNodeParameter('limit', i) as number };
|
||||
body.options = { top: this.getNodeParameter('limit', i) as number };
|
||||
|
||||
responseData = await quickbaseApiRequest.call(this, 'POST', '/records/query', body, qs);
|
||||
|
||||
|
||||
const { data: records, fields } = responseData;
|
||||
responseData = [];
|
||||
|
||||
|
@ -345,7 +346,7 @@ export class QuickBase implements INodeType {
|
|||
for (const field of fields) {
|
||||
fieldsIdKey[field.id] = field.label;
|
||||
}
|
||||
|
||||
|
||||
for (const record of records) {
|
||||
const data: IDataObject = {};
|
||||
for (const [key, value] of Object.entries(record)) {
|
||||
|
@ -389,7 +390,7 @@ export class QuickBase implements INodeType {
|
|||
}
|
||||
|
||||
record[fieldsLabelKey['Record ID#']] = { value: items[i].json[updateKey] };
|
||||
|
||||
|
||||
data.push(record);
|
||||
}
|
||||
|
||||
|
@ -410,7 +411,7 @@ export class QuickBase implements INodeType {
|
|||
if (simple === true) {
|
||||
const { data: records } = responseData;
|
||||
responseData = [];
|
||||
|
||||
|
||||
for (const record of records) {
|
||||
const data: IDataObject = {};
|
||||
for (const [key, value] of Object.entries(record)) {
|
||||
|
@ -460,7 +461,7 @@ export class QuickBase implements INodeType {
|
|||
}
|
||||
|
||||
record[mergeFieldId] = { value: items[i].json[updateKey] };
|
||||
|
||||
|
||||
data.push(record);
|
||||
}
|
||||
|
||||
|
@ -482,7 +483,7 @@ export class QuickBase implements INodeType {
|
|||
if (simple === true) {
|
||||
const { data: records } = responseData;
|
||||
responseData = [];
|
||||
|
||||
|
||||
for (const record of records) {
|
||||
const data: IDataObject = {};
|
||||
for (const [key, value] of Object.entries(record)) {
|
||||
|
@ -516,7 +517,7 @@ export class QuickBase implements INodeType {
|
|||
if (returnAll) {
|
||||
responseData = await quickbaseApiRequestAllItems.call(this, 'POST', `/reports/${reportId}/run`, {}, qs);
|
||||
} else {
|
||||
qs.top = this.getNodeParameter('limit', i) as number;
|
||||
qs.top = this.getNodeParameter('limit', i) as number;
|
||||
|
||||
responseData = await quickbaseApiRequest.call(this, 'POST', `/reports/${reportId}/run`, {}, qs);
|
||||
|
||||
|
@ -528,7 +529,7 @@ export class QuickBase implements INodeType {
|
|||
for (const field of fields) {
|
||||
fieldsIdKey[field.id] = field.label;
|
||||
}
|
||||
|
||||
|
||||
for (const record of records) {
|
||||
const data: IDataObject = {};
|
||||
for (const [key, value] of Object.entries(record)) {
|
||||
|
|
|
@ -83,6 +83,7 @@ export const recordFields = [
|
|||
},
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
placeholder: 'id,name,description',
|
||||
description: 'Comma separated list of the properties which should used as columns for the new rows.',
|
||||
},
|
||||
|
@ -363,7 +364,7 @@ export const recordFields = [
|
|||
name: 'where',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The filter, using the <a href="https://help.quickbase.com/api-guide/componentsquery.html" target="_blank">Quick Base query language</a>, which determines the records to return.',
|
||||
description: 'The filter, using the <a href="https://help.quickbase.com/api-guide/componentsquery.html" target="_blank">Quick Base query language</a>, which determines the records to return.',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -403,6 +404,7 @@ export const recordFields = [
|
|||
},
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
placeholder: 'id,name,description',
|
||||
description: 'Comma separated list of the properties which should used as columns for the new rows.',
|
||||
},
|
||||
|
@ -520,6 +522,7 @@ export const recordFields = [
|
|||
},
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
placeholder: 'id,name,description',
|
||||
description: 'Comma separated list of the properties which should used as columns for the new rows.',
|
||||
},
|
||||
|
|
|
@ -51,7 +51,7 @@ export const reportFields = [
|
|||
],
|
||||
},
|
||||
},
|
||||
description: 'The table identifier',
|
||||
description: 'The table identifier.',
|
||||
},
|
||||
{
|
||||
displayName: 'Report ID',
|
||||
|
@ -69,7 +69,7 @@ export const reportFields = [
|
|||
],
|
||||
},
|
||||
},
|
||||
description: 'The identifier of the report, unique to the table',
|
||||
description: 'The identifier of the report, unique to the table.',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* report:run */
|
||||
|
@ -90,7 +90,7 @@ export const reportFields = [
|
|||
],
|
||||
},
|
||||
},
|
||||
description: 'The table identifier',
|
||||
description: 'The table identifier.',
|
||||
},
|
||||
{
|
||||
displayName: 'Report ID',
|
||||
|
@ -108,7 +108,7 @@ export const reportFields = [
|
|||
],
|
||||
},
|
||||
},
|
||||
description: 'The identifier of the report, unique to the table',
|
||||
description: 'The identifier of the report, unique to the table.',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in a new issue