Skip to content

Commit

Permalink
chunk the array
Browse files Browse the repository at this point in the history
  • Loading branch information
hassan254-prog committed Jan 12, 2024
1 parent cb813c7 commit bc32ebe
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions integration-templates/bamboohr/bamboohr-employees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ export default async function fetchData(nango: NangoSync) {
data: customReportData
});

const mappedEmployees = mapEmployee(response.data.employees);
const batchSize = mappedEmployees.length;
totalRecords += batchSize;
await nango.log(`Saving batch of ${batchSize} employee(s) (total employee(s): ${totalRecords})`);
await nango.batchSave(mappedEmployees, 'BamboohrEmployee');
const employees = response.data.employees;
const chunkSize = 100;

for (let i = 0; i < employees.length; i += chunkSize) {
const chunk = employees.slice(i, i + chunkSize);
const mappedEmployees = mapEmployee(chunk);
const batchSize = mappedEmployees.length;
totalRecords += batchSize;

await nango.log(`Saving batch of ${batchSize} employee(s)`);
await nango.batchSave(mappedEmployees, 'BamboohrEmployee');
}

await nango.log(`Total employee(s) processed: ${employees.length}`);
} catch (error: any) {
throw new Error(`Error in fetchData: ${error.message}`);
}
Expand Down

0 comments on commit bc32ebe

Please sign in to comment.