sr-npm 1.7.265 → 1.7.267
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { fetch } = require('wix-fetch');
|
|
2
2
|
const { items: wixData } = require('@wix/data');
|
|
3
3
|
const { COLLECTIONS } = require('./collectionConsts');
|
|
4
|
-
const
|
|
4
|
+
const secretsData = require('./secretsData');
|
|
5
5
|
async function makeSmartRecruitersRequest(path,token) {
|
|
6
6
|
const baseUrl = 'https://api.smartrecruiters.com'; // PROD
|
|
7
7
|
// const baseUrl = 'https://bayank2.wixstudio.com/my-site-3//_functions'; // TEST
|
|
@@ -38,7 +38,7 @@ async function fetchPositionsFromSRAPI() {
|
|
|
38
38
|
let page = 0;
|
|
39
39
|
const MAX_PAGES = 30 // Safety limit to prevent infinite loops
|
|
40
40
|
const token = await getSmartTokenFromCMS();
|
|
41
|
-
const companyId=await getCompanyId();
|
|
41
|
+
const companyId = await secretsData.getCompanyId();
|
|
42
42
|
console.log('Starting to fetch all positions with pagination...');
|
|
43
43
|
let offset=0;
|
|
44
44
|
|
|
@@ -47,10 +47,7 @@ async function fetchPositionsFromSRAPI() {
|
|
|
47
47
|
page++;
|
|
48
48
|
|
|
49
49
|
// Build the API path - first request has no page parameter, subsequent use nextPageId
|
|
50
|
-
let apiPath = `/v1/companies/${companyId}/postings?offset=${offset}`;
|
|
51
|
-
if (nextPageId) {
|
|
52
|
-
apiPath += `&pageId=${nextPageId}`;
|
|
53
|
-
}
|
|
50
|
+
let apiPath = `/v1/companies/${companyId.value}/postings?offset=${offset}&limit=10`;
|
|
54
51
|
|
|
55
52
|
console.log(`Fetching page ${page} with path: ${apiPath}`);
|
|
56
53
|
const response = await makeSmartRecruitersRequest(apiPath,token);
|
|
@@ -69,13 +66,9 @@ async function fetchPositionsFromSRAPI() {
|
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
// Get the nextPageId for the next iteration
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
console.log(`Next page ID: ${nextPageId}`);
|
|
76
|
-
} else {
|
|
77
|
-
console.log('No more pages to fetch');
|
|
78
|
-
}
|
|
69
|
+
// nextPageId = response.nextPageId && response.nextPageId !== '' ? response.nextPageId : null;
|
|
70
|
+
offset+=10;
|
|
71
|
+
|
|
79
72
|
} catch (error) {
|
|
80
73
|
console.error(`Error fetching page ${page}:`, error);
|
|
81
74
|
throw error;
|
|
@@ -86,7 +79,7 @@ async function fetchPositionsFromSRAPI() {
|
|
|
86
79
|
console.warn(`Reached maximum page limit of ${MAX_PAGES}. Stopping pagination.`);
|
|
87
80
|
break;
|
|
88
81
|
}
|
|
89
|
-
} while (
|
|
82
|
+
} while (offset<totalFound); // Continue while there's a nextPageId
|
|
90
83
|
|
|
91
84
|
console.log(`Finished fetching all pages. Total positions collected: ${allPositions.length}`);
|
|
92
85
|
|