mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -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;
|
const action = this.getNodeParameter('action', 0) as string;
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
try {
|
||||||
// Reset all values
|
for (let i = 0; i < items.length; i++) {
|
||||||
requestOptions = {
|
// Reset all values
|
||||||
uri: '',
|
requestOptions = {
|
||||||
headers: {
|
uri: '',
|
||||||
'Authorization': `Bearer ${token}`,
|
headers: {
|
||||||
},
|
'Authorization': `Bearer ${token}`,
|
||||||
method: 'GET',
|
},
|
||||||
json: true
|
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)
|
|
||||||
};
|
};
|
||||||
} else if (action === 'records') {
|
|
||||||
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records`;
|
const layout = this.getNodeParameter('layout', i) as string;
|
||||||
requestOptions.qs = {
|
|
||||||
'_offset': this.getNodeParameter('offset', 0),
|
if (action === 'record') {
|
||||||
'_limit': this.getNodeParameter('limit', 0),
|
const recid = this.getNodeParameter('recid', i) as string;
|
||||||
'portal': JSON.stringify(parsePortals.call(this)),
|
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
|
||||||
...parseScripts.call(this)
|
requestOptions.qs = {
|
||||||
};
|
'portal': JSON.stringify(parsePortals.call(this, i)),
|
||||||
const sort = parseSort.call(this);
|
...parseScripts.call(this, i)
|
||||||
if (sort) {
|
};
|
||||||
requestOptions.body.sort = sort;
|
} 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`;
|
// Now that the options are all set make the actual http request
|
||||||
requestOptions.method = 'POST';
|
let response;
|
||||||
requestOptions.body = {
|
try {
|
||||||
'query': parseQuery.call(this),
|
response = await this.helpers.request(requestOptions);
|
||||||
'offset': this.getNodeParameter('offset', 0),
|
} catch (error) {
|
||||||
'limit': this.getNodeParameter('limit', 0),
|
response = error.response.body;
|
||||||
'layout.response': this.getNodeParameter('responseLayout', 0),
|
|
||||||
...parseScripts.call(this)
|
|
||||||
};
|
|
||||||
const sort = parseSort.call(this);
|
|
||||||
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
|
if (typeof response === 'string') {
|
||||||
requestOptions.body = {
|
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
|
||||||
fieldData: {...parseFields.call(this)},
|
}
|
||||||
portalData: {},
|
returnData.push({json: response});
|
||||||
...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"');
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
await logout.call(this, token);
|
await logout.call(this, token);
|
||||||
|
throw new Error(`The action "${error.message}" is not implemented yet!`);
|
||||||
returnData.push({json: response});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.prepareOutputData(returnData);
|
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;
|
let sort;
|
||||||
const setSort = this.getNodeParameter('setSort', 0, false);
|
const setSort = this.getNodeParameter('setSort', i, false);
|
||||||
if (!setSort) {
|
if (!setSort) {
|
||||||
sort = null;
|
sort = null;
|
||||||
} else {
|
} else {
|
||||||
sort = [];
|
sort = [];
|
||||||
const sortParametersUi = this.getNodeParameter('sortParametersUi', 0, {}) as IDataObject;
|
const sortParametersUi = this.getNodeParameter('sortParametersUi', i, {}) as IDataObject;
|
||||||
if (sortParametersUi.rules !== undefined) {
|
if (sortParametersUi.rules !== undefined) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
for (const parameterData of sortParametersUi!.rules as IDataObject[]) {
|
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 {
|
export function parseScripts(this: IExecuteFunctions, i: number): object | null {
|
||||||
const setScriptAfter = this.getNodeParameter('setScriptAfter', 0, false);
|
const setScriptAfter = this.getNodeParameter('setScriptAfter', i, false);
|
||||||
const setScriptBefore = this.getNodeParameter('setScriptBefore', 0, false);
|
const setScriptBefore = this.getNodeParameter('setScriptBefore', i, false);
|
||||||
const setScriptSort = this.getNodeParameter('setScriptSort', 0, false);
|
const setScriptSort = this.getNodeParameter('setScriptSort', i, false);
|
||||||
|
|
||||||
if (!setScriptAfter && setScriptBefore && setScriptSort) {
|
if (!setScriptAfter && setScriptBefore && setScriptSort) {
|
||||||
return {};
|
return {};
|
||||||
} else {
|
} else {
|
||||||
const scripts = {} as ScriptsOptions;
|
const scripts = {} as ScriptsOptions;
|
||||||
if (setScriptAfter) {
|
if (setScriptAfter) {
|
||||||
scripts.script = this.getNodeParameter('scriptAfter', 0);
|
scripts.script = this.getNodeParameter('scriptAfter', i);
|
||||||
scripts!['script.param'] = this.getNodeParameter('scriptAfter', 0);
|
scripts!['script.param'] = this.getNodeParameter('scriptAfter', i);
|
||||||
}
|
}
|
||||||
if (setScriptBefore) {
|
if (setScriptBefore) {
|
||||||
scripts['script.prerequest'] = this.getNodeParameter('scriptBefore', 0);
|
scripts['script.prerequest'] = this.getNodeParameter('scriptBefore', i);
|
||||||
scripts['script.prerequest.param'] = this.getNodeParameter('scriptBeforeParam', 0);
|
scripts['script.prerequest.param'] = this.getNodeParameter('scriptBeforeParam', i);
|
||||||
}
|
}
|
||||||
if (setScriptSort) {
|
if (setScriptSort) {
|
||||||
scripts['script.presort'] = this.getNodeParameter('scriptSort', 0);
|
scripts['script.presort'] = this.getNodeParameter('scriptSort', i);
|
||||||
scripts['script.presort.param'] = this.getNodeParameter('scriptSortParam', 0);
|
scripts['script.presort.param'] = this.getNodeParameter('scriptSortParam', i);
|
||||||
}
|
}
|
||||||
return scripts;
|
return scripts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parsePortals(this: IExecuteFunctions): object | null {
|
export function parsePortals(this: IExecuteFunctions, i: number): object | null {
|
||||||
let portals;
|
let portals;
|
||||||
const getPortals = this.getNodeParameter('getPortals', 0);
|
const getPortals = this.getNodeParameter('getPortals', i);
|
||||||
if (!getPortals) {
|
if (!getPortals) {
|
||||||
portals = [];
|
portals = [];
|
||||||
} else {
|
} else {
|
||||||
portals = this.getNodeParameter('portals', 0);
|
portals = this.getNodeParameter('portals', i);
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return portals;
|
return portals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function parseQuery(this: IExecuteFunctions): object | null {
|
export function parseQuery(this: IExecuteFunctions, i: number): object | null {
|
||||||
let queries;
|
let queries;
|
||||||
const queriesParamUi = this.getNodeParameter('queries', 0, {}) as IDataObject;
|
const queriesParamUi = this.getNodeParameter('queries', i, {}) as IDataObject;
|
||||||
if (queriesParamUi.query !== undefined) {
|
if (queriesParamUi.query !== undefined) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
queries = [];
|
queries = [];
|
||||||
|
@ -372,9 +372,9 @@ export function parseQuery(this: IExecuteFunctions): object | null {
|
||||||
return queries;
|
return queries;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseFields(this: IExecuteFunctions): object | null {
|
export function parseFields(this: IExecuteFunctions, i: number): object | null {
|
||||||
let fieldData;
|
let fieldData;
|
||||||
const fieldsParametersUi = this.getNodeParameter('fieldsParametersUi', 0, {}) as IDataObject;
|
const fieldsParametersUi = this.getNodeParameter('fieldsParametersUi', i, {}) as IDataObject;
|
||||||
if (fieldsParametersUi.fields !== undefined) {
|
if (fieldsParametersUi.fields !== undefined) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
fieldData = {};
|
fieldData = {};
|
||||||
|
|
Loading…
Reference in a new issue