mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
Fix an issue with logout and items parameter
parameters where not populate using the correct item index Logout after the loop across items
This commit is contained in:
parent
2b80d231be
commit
b8dd8a4b39
|
@ -794,114 +794,117 @@ export class FileMaker implements INodeType {
|
|||
|
||||
const action = this.getNodeParameter('action', 0) as string;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
// Reset all values
|
||||
requestOptions = {
|
||||
uri: '',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
method: 'GET',
|
||||
json: true
|
||||
};
|
||||
|
||||
const layout = this.getNodeParameter('layout', 0) as string;
|
||||
|
||||
if (action === 'record') {
|
||||
const recid = this.getNodeParameter('recid', 0) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
|
||||
requestOptions.qs = {
|
||||
'portal': JSON.stringify(parsePortals.call(this)),
|
||||
...parseScripts.call(this)
|
||||
try {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
// Reset all values
|
||||
requestOptions = {
|
||||
uri: '',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
method: 'GET',
|
||||
json: true
|
||||
};
|
||||
} else if (action === 'records') {
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records`;
|
||||
requestOptions.qs = {
|
||||
'_offset': this.getNodeParameter('offset', 0),
|
||||
'_limit': this.getNodeParameter('limit', 0),
|
||||
'portal': JSON.stringify(parsePortals.call(this)),
|
||||
...parseScripts.call(this)
|
||||
};
|
||||
const sort = parseSort.call(this);
|
||||
if (sort) {
|
||||
requestOptions.body.sort = sort;
|
||||
|
||||
const layout = this.getNodeParameter('layout', i) as string;
|
||||
|
||||
if (action === 'record') {
|
||||
const recid = this.getNodeParameter('recid', i) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
|
||||
requestOptions.qs = {
|
||||
'portal': JSON.stringify(parsePortals.call(this, i)),
|
||||
...parseScripts.call(this, i)
|
||||
};
|
||||
} else if (action === 'records') {
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records`;
|
||||
requestOptions.qs = {
|
||||
'_offset': this.getNodeParameter('offset', i),
|
||||
'_limit': this.getNodeParameter('limit', i),
|
||||
'portal': JSON.stringify(parsePortals.call(this, i)),
|
||||
...parseScripts.call(this, i)
|
||||
};
|
||||
const sort = parseSort.call(this, i);
|
||||
if (sort) {
|
||||
requestOptions.body.sort = sort;
|
||||
}
|
||||
} else if (action === 'find') {
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/_find`;
|
||||
requestOptions.method = 'POST';
|
||||
requestOptions.body = {
|
||||
'query': parseQuery.call(this, i),
|
||||
'offset': this.getNodeParameter('offset', i),
|
||||
'limit': this.getNodeParameter('limit', i),
|
||||
'layout.response': this.getNodeParameter('responseLayout', i),
|
||||
...parseScripts.call(this, i)
|
||||
};
|
||||
const sort = parseSort.call(this, i);
|
||||
if (sort) {
|
||||
requestOptions.body.sort = sort;
|
||||
}
|
||||
} else if (action === 'create') {
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records`;
|
||||
requestOptions.method = 'POST';
|
||||
requestOptions.headers!['Content-Type'] = 'application/json';
|
||||
|
||||
//TODO: handle portalData
|
||||
requestOptions.body = {
|
||||
fieldData: {...parseFields.call(this, i)},
|
||||
portalData: {},
|
||||
...parseScripts.call(this, i)
|
||||
};
|
||||
} else if (action === 'edit') {
|
||||
const recid = this.getNodeParameter('recid', i) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
|
||||
requestOptions.method = 'PATCH';
|
||||
requestOptions.headers!['Content-Type'] = 'application/json';
|
||||
|
||||
//TODO: handle portalData
|
||||
requestOptions.body = {
|
||||
fieldData: {...parseFields.call(this, i)},
|
||||
portalData: {},
|
||||
...parseScripts.call(this, i)
|
||||
};
|
||||
} else if (action === 'performscript') {
|
||||
const scriptName = this.getNodeParameter('script', i) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/script/${scriptName}`;
|
||||
requestOptions.qs = {
|
||||
'script.param': this.getNodeParameter('scriptParam', i),
|
||||
};
|
||||
} else if (action === 'duplicate') {
|
||||
const recid = this.getNodeParameter('recid', i) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
|
||||
requestOptions.method = 'POST';
|
||||
requestOptions.headers!['Content-Type'] = 'application/json';
|
||||
requestOptions.qs = {
|
||||
...parseScripts.call(this, i)
|
||||
};
|
||||
} else if (action === 'delete') {
|
||||
const recid = this.getNodeParameter('recid', i) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
|
||||
requestOptions.method = 'DELETE';
|
||||
requestOptions.qs = {
|
||||
...parseScripts.call(this, i)
|
||||
};
|
||||
} else {
|
||||
throw new Error(`The action "${action}" is not implemented yet!`);
|
||||
}
|
||||
} else if (action === 'find') {
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/_find`;
|
||||
requestOptions.method = 'POST';
|
||||
requestOptions.body = {
|
||||
'query': parseQuery.call(this),
|
||||
'offset': this.getNodeParameter('offset', 0),
|
||||
'limit': this.getNodeParameter('limit', 0),
|
||||
'layout.response': this.getNodeParameter('responseLayout', 0),
|
||||
...parseScripts.call(this)
|
||||
};
|
||||
const sort = parseSort.call(this);
|
||||
if (sort) {
|
||||
requestOptions.body.sort = sort;
|
||||
|
||||
// Now that the options are all set make the actual http request
|
||||
let response;
|
||||
try {
|
||||
response = await this.helpers.request(requestOptions);
|
||||
} catch (error) {
|
||||
response = error.response.body;
|
||||
}
|
||||
} else if (action === 'create') {
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records`;
|
||||
requestOptions.method = 'POST';
|
||||
requestOptions.headers!['Content-Type'] = 'application/json';
|
||||
|
||||
//TODO: handle portalData
|
||||
requestOptions.body = {
|
||||
fieldData: {...parseFields.call(this)},
|
||||
portalData: {},
|
||||
...parseScripts.call(this)
|
||||
};
|
||||
} else if (action === 'edit') {
|
||||
const recid = this.getNodeParameter('recid', 0) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
|
||||
requestOptions.method = 'PATCH';
|
||||
requestOptions.headers!['Content-Type'] = 'application/json';
|
||||
|
||||
//TODO: handle portalData
|
||||
requestOptions.body = {
|
||||
fieldData: {...parseFields.call(this)},
|
||||
portalData: {},
|
||||
...parseScripts.call(this)
|
||||
};
|
||||
} else if (action === 'performscript') {
|
||||
const scriptName = this.getNodeParameter('script', 0) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/script/${scriptName}`;
|
||||
requestOptions.qs = {
|
||||
'script.param': this.getNodeParameter('scriptParam', 0),
|
||||
};
|
||||
} else if (action === 'duplicate') {
|
||||
const recid = this.getNodeParameter('recid', 0) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
|
||||
requestOptions.method = 'POST';
|
||||
requestOptions.headers!['Content-Type'] = 'application/json';
|
||||
requestOptions.qs = {
|
||||
...parseScripts.call(this)
|
||||
};
|
||||
} else if (action === 'delete') {
|
||||
const recid = this.getNodeParameter('recid', 0) as string;
|
||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
|
||||
requestOptions.method = 'DELETE';
|
||||
requestOptions.qs = {
|
||||
...parseScripts.call(this)
|
||||
};
|
||||
} else {
|
||||
throw new Error(`The action "${action}" is not implemented yet!`);
|
||||
}
|
||||
|
||||
// Now that the options are all set make the actual http request
|
||||
let response;
|
||||
try {
|
||||
response = await this.helpers.request(requestOptions);
|
||||
} catch (error) {
|
||||
response = error.response.body;
|
||||
}
|
||||
|
||||
if (typeof response === 'string') {
|
||||
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
|
||||
if (typeof response === 'string') {
|
||||
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
|
||||
}
|
||||
returnData.push({json: response});
|
||||
}
|
||||
} catch (error) {
|
||||
await logout.call(this, token);
|
||||
|
||||
returnData.push({json: response});
|
||||
throw new Error(`The action "${error.message}" is not implemented yet!`);
|
||||
}
|
||||
|
||||
return this.prepareOutputData(returnData);
|
||||
|
|
|
@ -287,14 +287,14 @@ export async function logout(this: ILoadOptionsFunctions | IExecuteFunctions | I
|
|||
}
|
||||
}
|
||||
|
||||
export function parseSort(this: IExecuteFunctions): object | null {
|
||||
export function parseSort(this: IExecuteFunctions, i: number): object | null {
|
||||
let sort;
|
||||
const setSort = this.getNodeParameter('setSort', 0, false);
|
||||
const setSort = this.getNodeParameter('setSort', i, false);
|
||||
if (!setSort) {
|
||||
sort = null;
|
||||
} else {
|
||||
sort = [];
|
||||
const sortParametersUi = this.getNodeParameter('sortParametersUi', 0, {}) as IDataObject;
|
||||
const sortParametersUi = this.getNodeParameter('sortParametersUi', i, {}) as IDataObject;
|
||||
if (sortParametersUi.rules !== undefined) {
|
||||
// @ts-ignore
|
||||
for (const parameterData of sortParametersUi!.rules as IDataObject[]) {
|
||||
|
@ -310,47 +310,47 @@ export function parseSort(this: IExecuteFunctions): object | null {
|
|||
}
|
||||
|
||||
|
||||
export function parseScripts(this: IExecuteFunctions): object | null {
|
||||
const setScriptAfter = this.getNodeParameter('setScriptAfter', 0, false);
|
||||
const setScriptBefore = this.getNodeParameter('setScriptBefore', 0, false);
|
||||
const setScriptSort = this.getNodeParameter('setScriptSort', 0, false);
|
||||
export function parseScripts(this: IExecuteFunctions, i: number): object | null {
|
||||
const setScriptAfter = this.getNodeParameter('setScriptAfter', i, false);
|
||||
const setScriptBefore = this.getNodeParameter('setScriptBefore', i, false);
|
||||
const setScriptSort = this.getNodeParameter('setScriptSort', i, false);
|
||||
|
||||
if (!setScriptAfter && setScriptBefore && setScriptSort) {
|
||||
return {};
|
||||
} else {
|
||||
const scripts = {} as ScriptsOptions;
|
||||
if (setScriptAfter) {
|
||||
scripts.script = this.getNodeParameter('scriptAfter', 0);
|
||||
scripts!['script.param'] = this.getNodeParameter('scriptAfter', 0);
|
||||
scripts.script = this.getNodeParameter('scriptAfter', i);
|
||||
scripts!['script.param'] = this.getNodeParameter('scriptAfter', i);
|
||||
}
|
||||
if (setScriptBefore) {
|
||||
scripts['script.prerequest'] = this.getNodeParameter('scriptBefore', 0);
|
||||
scripts['script.prerequest.param'] = this.getNodeParameter('scriptBeforeParam', 0);
|
||||
scripts['script.prerequest'] = this.getNodeParameter('scriptBefore', i);
|
||||
scripts['script.prerequest.param'] = this.getNodeParameter('scriptBeforeParam', i);
|
||||
}
|
||||
if (setScriptSort) {
|
||||
scripts['script.presort'] = this.getNodeParameter('scriptSort', 0);
|
||||
scripts['script.presort.param'] = this.getNodeParameter('scriptSortParam', 0);
|
||||
scripts['script.presort'] = this.getNodeParameter('scriptSort', i);
|
||||
scripts['script.presort.param'] = this.getNodeParameter('scriptSortParam', i);
|
||||
}
|
||||
return scripts;
|
||||
}
|
||||
}
|
||||
|
||||
export function parsePortals(this: IExecuteFunctions): object | null {
|
||||
export function parsePortals(this: IExecuteFunctions, i: number): object | null {
|
||||
let portals;
|
||||
const getPortals = this.getNodeParameter('getPortals', 0);
|
||||
const getPortals = this.getNodeParameter('getPortals', i);
|
||||
if (!getPortals) {
|
||||
portals = [];
|
||||
} else {
|
||||
portals = this.getNodeParameter('portals', 0);
|
||||
portals = this.getNodeParameter('portals', i);
|
||||
}
|
||||
// @ts-ignore
|
||||
return portals;
|
||||
}
|
||||
|
||||
|
||||
export function parseQuery(this: IExecuteFunctions): object | null {
|
||||
export function parseQuery(this: IExecuteFunctions, i: number): object | null {
|
||||
let queries;
|
||||
const queriesParamUi = this.getNodeParameter('queries', 0, {}) as IDataObject;
|
||||
const queriesParamUi = this.getNodeParameter('queries', i, {}) as IDataObject;
|
||||
if (queriesParamUi.query !== undefined) {
|
||||
// @ts-ignore
|
||||
queries = [];
|
||||
|
@ -372,9 +372,9 @@ export function parseQuery(this: IExecuteFunctions): object | null {
|
|||
return queries;
|
||||
}
|
||||
|
||||
export function parseFields(this: IExecuteFunctions): object | null {
|
||||
export function parseFields(this: IExecuteFunctions, i: number): object | null {
|
||||
let fieldData;
|
||||
const fieldsParametersUi = this.getNodeParameter('fieldsParametersUi', 0, {}) as IDataObject;
|
||||
const fieldsParametersUi = this.getNodeParameter('fieldsParametersUi', i, {}) as IDataObject;
|
||||
if (fieldsParametersUi.fields !== undefined) {
|
||||
// @ts-ignore
|
||||
fieldData = {};
|
||||
|
|
Loading…
Reference in a new issue