fix(Linear Node): Fix issue with data not always being returned (#9273)

Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
Jon
2024-05-08 10:24:08 +01:00
committed by GitHub
parent 3860077f81
commit 435272b568
3 changed files with 16 additions and 9 deletions

View File

@@ -52,20 +52,30 @@ export function capitalizeFirstLetter(data: string) {
export async function linearApiRequestAllItems(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
propertyName: string,
body: any = {},
limit?: number,
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
body.variables.first = 50;
body.variables.first = limit && limit < 50 ? limit : 50;
body.variables.after = null;
const propertyPath = propertyName.split('.');
const nodesPath = [...propertyPath, 'nodes'];
const endCursorPath = [...propertyPath, 'pageInfo', 'endCursor'];
const hasNextPagePath = [...propertyPath, 'pageInfo', 'hasNextPage'];
do {
responseData = await linearApiRequest.call(this, body);
returnData.push.apply(returnData, get(responseData, [propertyName, 'nodes']) as IDataObject[]);
body.variables.after = get(responseData, [propertyName, 'pageInfo', 'endCursor']);
} while (get(responseData, [propertyName, 'pageInfo', 'hasNextPage']));
const nodes = get(responseData, nodesPath) as IDataObject[];
returnData.push(...nodes);
body.variables.after = get(responseData, endCursorPath);
if (limit && returnData.length >= limit) {
return returnData;
}
} while (get(responseData, hasNextPagePath));
return returnData;
}