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:
Romain Dunand 2020-03-13 19:51:45 +01:00
parent 2b80d231be
commit b8dd8a4b39
2 changed files with 125 additions and 122 deletions

View file

@ -794,6 +794,7 @@ export class FileMaker implements INodeType {
const action = this.getNodeParameter('action', 0) as string; const action = this.getNodeParameter('action', 0) as string;
try {
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
// Reset all values // Reset all values
requestOptions = { requestOptions = {
@ -805,24 +806,24 @@ export class FileMaker implements INodeType {
json: true json: true
}; };
const layout = this.getNodeParameter('layout', 0) as string; const layout = this.getNodeParameter('layout', i) as string;
if (action === 'record') { if (action === 'record') {
const recid = this.getNodeParameter('recid', 0) as string; const recid = this.getNodeParameter('recid', i) as string;
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`; requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
requestOptions.qs = { requestOptions.qs = {
'portal': JSON.stringify(parsePortals.call(this)), 'portal': JSON.stringify(parsePortals.call(this, i)),
...parseScripts.call(this) ...parseScripts.call(this, i)
}; };
} else if (action === 'records') { } else if (action === 'records') {
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records`; requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records`;
requestOptions.qs = { requestOptions.qs = {
'_offset': this.getNodeParameter('offset', 0), '_offset': this.getNodeParameter('offset', i),
'_limit': this.getNodeParameter('limit', 0), '_limit': this.getNodeParameter('limit', i),
'portal': JSON.stringify(parsePortals.call(this)), 'portal': JSON.stringify(parsePortals.call(this, i)),
...parseScripts.call(this) ...parseScripts.call(this, i)
}; };
const sort = parseSort.call(this); const sort = parseSort.call(this, i);
if (sort) { if (sort) {
requestOptions.body.sort = sort; requestOptions.body.sort = sort;
} }
@ -830,13 +831,13 @@ export class FileMaker implements INodeType {
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/_find`; requestOptions.uri = url + `/databases/${database}/layouts/${layout}/_find`;
requestOptions.method = 'POST'; requestOptions.method = 'POST';
requestOptions.body = { requestOptions.body = {
'query': parseQuery.call(this), 'query': parseQuery.call(this, i),
'offset': this.getNodeParameter('offset', 0), 'offset': this.getNodeParameter('offset', i),
'limit': this.getNodeParameter('limit', 0), 'limit': this.getNodeParameter('limit', i),
'layout.response': this.getNodeParameter('responseLayout', 0), 'layout.response': this.getNodeParameter('responseLayout', i),
...parseScripts.call(this) ...parseScripts.call(this, i)
}; };
const sort = parseSort.call(this); const sort = parseSort.call(this, i);
if (sort) { if (sort) {
requestOptions.body.sort = sort; requestOptions.body.sort = sort;
} }
@ -847,42 +848,42 @@ export class FileMaker implements INodeType {
//TODO: handle portalData //TODO: handle portalData
requestOptions.body = { requestOptions.body = {
fieldData: {...parseFields.call(this)}, fieldData: {...parseFields.call(this, i)},
portalData: {}, portalData: {},
...parseScripts.call(this) ...parseScripts.call(this, i)
}; };
} else if (action === 'edit') { } else if (action === 'edit') {
const recid = this.getNodeParameter('recid', 0) as string; const recid = this.getNodeParameter('recid', i) as string;
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`; requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
requestOptions.method = 'PATCH'; requestOptions.method = 'PATCH';
requestOptions.headers!['Content-Type'] = 'application/json'; requestOptions.headers!['Content-Type'] = 'application/json';
//TODO: handle portalData //TODO: handle portalData
requestOptions.body = { requestOptions.body = {
fieldData: {...parseFields.call(this)}, fieldData: {...parseFields.call(this, i)},
portalData: {}, portalData: {},
...parseScripts.call(this) ...parseScripts.call(this, i)
}; };
} else if (action === 'performscript') { } else if (action === 'performscript') {
const scriptName = this.getNodeParameter('script', 0) as string; const scriptName = this.getNodeParameter('script', i) as string;
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/script/${scriptName}`; requestOptions.uri = url + `/databases/${database}/layouts/${layout}/script/${scriptName}`;
requestOptions.qs = { requestOptions.qs = {
'script.param': this.getNodeParameter('scriptParam', 0), 'script.param': this.getNodeParameter('scriptParam', i),
}; };
} else if (action === 'duplicate') { } else if (action === 'duplicate') {
const recid = this.getNodeParameter('recid', 0) as string; const recid = this.getNodeParameter('recid', i) as string;
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`; requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
requestOptions.method = 'POST'; requestOptions.method = 'POST';
requestOptions.headers!['Content-Type'] = 'application/json'; requestOptions.headers!['Content-Type'] = 'application/json';
requestOptions.qs = { requestOptions.qs = {
...parseScripts.call(this) ...parseScripts.call(this, i)
}; };
} else if (action === 'delete') { } else if (action === 'delete') {
const recid = this.getNodeParameter('recid', 0) as string; const recid = this.getNodeParameter('recid', i) as string;
requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`; requestOptions.uri = url + `/databases/${database}/layouts/${layout}/records/${recid}`;
requestOptions.method = 'DELETE'; requestOptions.method = 'DELETE';
requestOptions.qs = { requestOptions.qs = {
...parseScripts.call(this) ...parseScripts.call(this, i)
}; };
} else { } else {
throw new Error(`The action "${action}" is not implemented yet!`); throw new Error(`The action "${action}" is not implemented yet!`);
@ -899,10 +900,12 @@ export class FileMaker implements INodeType {
if (typeof response === 'string') { if (typeof response === 'string') {
throw new Error('Response body is not valid JSON. Change "Response Format" to "String"'); throw new Error('Response body is not valid JSON. Change "Response Format" to "String"');
} }
await logout.call(this, token);
returnData.push({json: response}); returnData.push({json: response});
} }
} catch (error) {
await logout.call(this, token);
throw new Error(`The action "${error.message}" is not implemented yet!`);
}
return this.prepareOutputData(returnData); return this.prepareOutputData(returnData);
} }

View file

@ -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 = {};