sr-npm 1.7.367 → 1.7.369
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.
|
@@ -2,7 +2,7 @@ const COLLECTIONS = {
|
|
|
2
2
|
AMOUNT_OF_JOBS_PER_DEPARTMENT: 'AmountOfJobsPerDepartment',
|
|
3
3
|
CITIES: 'cities',
|
|
4
4
|
JOBS: 'Jobs',
|
|
5
|
-
|
|
5
|
+
COMPANY_ID: 'CompanyId',
|
|
6
6
|
}
|
|
7
7
|
const JOBS_COLLECTION_FIELDS = {
|
|
8
8
|
LOCATION: 'location',
|
|
@@ -59,8 +59,8 @@ const COLLECTIONS_FIELDS = {
|
|
|
59
59
|
{key:'city', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CITIES } } },
|
|
60
60
|
{ key: 'image', type: 'IMAGE' },
|
|
61
61
|
],
|
|
62
|
-
|
|
63
|
-
{key:'
|
|
62
|
+
COMPANY_ID: [
|
|
63
|
+
{key:'companyId', type: 'TEXT'},
|
|
64
64
|
],
|
|
65
65
|
};
|
|
66
66
|
|
package/backend/consts.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const {saveJobsDataToCMS,saveJobsDescriptionsAndLocationApplyUrlToCMS,
|
|
2
|
-
|
|
3
|
-
const { COLLECTIONS, COLLECTIONS_FIELDS, JOBS_COLLECTION_FIELDS } = require('./collectionConsts');
|
|
1
|
+
const {saveJobsDataToCMS,saveJobsDescriptionsAndLocationApplyUrlToCMS,createCollections,aggregateJobs,referenceJobs,syncJobsFast} = require('./data')
|
|
2
|
+
|
|
4
3
|
|
|
5
4
|
const QUERY_MAX_LIMIT = 1000;
|
|
6
5
|
|
|
@@ -11,7 +10,7 @@ const TASKS_NAMES = {
|
|
|
11
10
|
AGGREGATE_JOBS_BY_FIELD_TO_CMS: 'aggregateJobsByFieldToCMS',
|
|
12
11
|
REFERENCE_JOBS: 'referenceJobs',
|
|
13
12
|
CREATE_COLLECTIONS: 'createCollections',
|
|
14
|
-
|
|
13
|
+
CREATE_COMPANY_ID_COLLECTION_AND_FILL_IT: 'createCompanyIdCollectionAndFillIt',
|
|
15
14
|
SYNC_JOBS_FAST: 'syncJobsFast',
|
|
16
15
|
}
|
|
17
16
|
|
|
@@ -64,20 +63,13 @@ const TASKS = {
|
|
|
64
63
|
shouldSkipCheck:()=>false,
|
|
65
64
|
estimatedDurationSec:6
|
|
66
65
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
[TASKS_NAMES.SYNC_JOBS_FAST]: {
|
|
75
|
-
name: TASKS_NAMES.SYNC_JOBS_FAST,
|
|
76
|
-
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
|
77
|
-
process:syncJobsFast,
|
|
78
|
-
shouldSkipCheck:()=>false,
|
|
79
|
-
estimatedDurationSec:60
|
|
80
|
-
}
|
|
66
|
+
[TASKS_NAMES.SYNC_JOBS_FAST]: {
|
|
67
|
+
name: TASKS_NAMES.SYNC_JOBS_FAST,
|
|
68
|
+
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
|
69
|
+
process:syncJobsFast,
|
|
70
|
+
shouldSkipCheck:()=>false,
|
|
71
|
+
estimatedDurationSec:60
|
|
72
|
+
}
|
|
81
73
|
}
|
|
82
74
|
|
|
83
75
|
|
package/backend/data.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const { items: wixData
|
|
1
|
+
const { items: wixData } = require('@wix/data');
|
|
2
2
|
const { fetchPositionsFromSRAPI, fetchJobDescription } = require('./fetchPositionsFromSRAPI');
|
|
3
3
|
const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend');
|
|
4
4
|
const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS } = require('./collectionConsts');
|
|
5
|
-
const { chunkedBulkOperation,
|
|
5
|
+
const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeCityName} = require('./utils');
|
|
6
6
|
const { getAllPositions } = require('./queries');
|
|
7
|
-
const {
|
|
7
|
+
const { getCompanyIdFromCMS } = require('./fetchPositionsFromSRAPI');
|
|
8
8
|
|
|
9
9
|
function validatePosition(position) {
|
|
10
10
|
if (!position.id) {
|
|
@@ -288,21 +288,21 @@ function fetchJobLocation(jobDetails) {
|
|
|
288
288
|
|
|
289
289
|
|
|
290
290
|
|
|
291
|
-
async function
|
|
292
|
-
console.log("Creating
|
|
293
|
-
await createCollectionIfMissing(COLLECTIONS.
|
|
294
|
-
console.log("Getting the
|
|
295
|
-
const
|
|
296
|
-
console.log("
|
|
297
|
-
console.log("Inserting the
|
|
291
|
+
async function createCompanyIdCollectionAndFillIt() {
|
|
292
|
+
console.log("Creating CompanyId collection and filling it with the company ID");
|
|
293
|
+
await createCollectionIfMissing(COLLECTIONS.COMPANY_ID, COLLECTIONS_FIELDS.COMPANY_ID,null,'singleItem');
|
|
294
|
+
console.log("Getting the company ID ");
|
|
295
|
+
const companyId = await getCompanyIdFromCMS();
|
|
296
|
+
console.log("companyId is : ", companyId);
|
|
297
|
+
console.log("Inserting the company ID into the CompanyId collection");
|
|
298
298
|
try {
|
|
299
|
-
await wixData.insert(COLLECTIONS.
|
|
300
|
-
|
|
299
|
+
await wixData.insert(COLLECTIONS.COMPANY_ID, {
|
|
300
|
+
companyId: companyId.value
|
|
301
301
|
});
|
|
302
|
-
console.log("
|
|
302
|
+
console.log("company ID inserted into the CompanyId collection");
|
|
303
303
|
} catch (error) {
|
|
304
304
|
if (error.message.includes("WDE0074: An item with _id [SINGLE_ITEM_ID] already exists")) {
|
|
305
|
-
console.log("
|
|
305
|
+
console.log("company ID already exists in the CompanyId collection");
|
|
306
306
|
}
|
|
307
307
|
else {
|
|
308
308
|
throw error;
|
|
@@ -340,7 +340,6 @@ async function referenceJobs() {
|
|
|
340
340
|
|
|
341
341
|
async function syncJobsFast() {
|
|
342
342
|
console.log("Syncing jobs fast");
|
|
343
|
-
//await createApiKeyCollectionAndFillIt();
|
|
344
343
|
await createCollections();
|
|
345
344
|
await clearCollections();
|
|
346
345
|
console.log("saving jobs data to CMS");
|
|
@@ -373,5 +372,5 @@ module.exports = {
|
|
|
373
372
|
saveJobsDescriptionsAndLocationApplyUrlToCMS,
|
|
374
373
|
aggregateJobsByFieldToCMS,
|
|
375
374
|
referenceJobsToField,
|
|
376
|
-
|
|
375
|
+
createCompanyIdCollectionAndFillIt,
|
|
377
376
|
};
|
|
@@ -33,7 +33,7 @@ async function fetchPositionsFromSRAPI() {
|
|
|
33
33
|
let totalFound = 0;
|
|
34
34
|
let page = 0;
|
|
35
35
|
const MAX_PAGES = 30 // Safety limit to prevent infinite loops
|
|
36
|
-
const companyId = await
|
|
36
|
+
const companyId = await getCompanyIdFromCMS();
|
|
37
37
|
console.log('Starting to fetch all positions with pagination...');
|
|
38
38
|
let offset=0;
|
|
39
39
|
|
|
@@ -95,16 +95,16 @@ async function fetchPositionsFromSRAPI() {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
async function fetchJobDescription(jobId) {
|
|
98
|
-
const companyId = await
|
|
98
|
+
const companyId = await getCompanyIdFromCMS();
|
|
99
99
|
return await makeSmartRecruitersRequest(`/v1/companies/${companyId.value}/postings/${jobId}`);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
async function
|
|
103
|
-
const result = await wixData.query(COLLECTIONS.
|
|
102
|
+
async function getCompanyIdFromCMS() {
|
|
103
|
+
const result = await wixData.query(COLLECTIONS.COMPANY_ID).limit(1).find();
|
|
104
104
|
if (result.items.length > 0) {
|
|
105
|
-
return result.items[0].
|
|
105
|
+
return result.items[0].companyId;
|
|
106
106
|
} else {
|
|
107
|
-
throw new Error('[
|
|
107
|
+
throw new Error('[getCompanyIdFromCMS], No companyId found');
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -112,4 +112,5 @@ async function getSmartTokenFromCMS() {
|
|
|
112
112
|
module.exports = {
|
|
113
113
|
fetchPositionsFromSRAPI,
|
|
114
114
|
fetchJobDescription,
|
|
115
|
+
getCompanyIdFromCMS
|
|
115
116
|
};
|
package/backend/secretsData.js
CHANGED
|
@@ -2,13 +2,6 @@ const { secrets } = require("@wix/secrets");
|
|
|
2
2
|
const { auth } = require('@wix/essentials');
|
|
3
3
|
|
|
4
4
|
const getSecretValue = auth.elevate(secrets.getSecretValue);
|
|
5
|
-
|
|
6
|
-
function getSmartToken() {
|
|
7
|
-
return getSecretValue("x-smarttoken")
|
|
8
|
-
.then((secret) => {
|
|
9
|
-
return secret;
|
|
10
|
-
})
|
|
11
|
-
}
|
|
12
5
|
|
|
13
6
|
function getCompanyId() {
|
|
14
7
|
return getSecretValue("companyID")
|
|
@@ -17,6 +10,5 @@ function getSmartToken() {
|
|
|
17
10
|
})
|
|
18
11
|
}
|
|
19
12
|
module.exports = {
|
|
20
|
-
getSmartToken,
|
|
21
13
|
getCompanyId
|
|
22
14
|
};
|
package/package.json
CHANGED
|
@@ -5,11 +5,11 @@ describe('Job details fetch from SR API Tests', () => {
|
|
|
5
5
|
|
|
6
6
|
test('should successfully fetch job details from SR API', async () => {
|
|
7
7
|
const requestBody = `fetchPositionsFromSRAPI();`;
|
|
8
|
-
const
|
|
9
|
-
const randomPosition = getRandomPosition(
|
|
8
|
+
const fetchJobsResponse = await executeApiRequest(requestBody);
|
|
9
|
+
const randomPosition = getRandomPosition(fetchJobsResponse.data.result.content);
|
|
10
10
|
console.log("randomPosition: ", randomPosition);
|
|
11
|
-
expect(
|
|
12
|
-
expect(
|
|
11
|
+
expect(fetchJobsResponse.data.result.totalFound).toBeGreaterThan(0);
|
|
12
|
+
expect(fetchJobsResponse.data.result.content.length).toBeGreaterThan(0);
|
|
13
13
|
expect(randomPosition.id.length).toBeGreaterThan(0);
|
|
14
14
|
expect(randomPosition.name.length).toBeGreaterThan(0);
|
|
15
15
|
expect(randomPosition.jobAdId.length).toBeGreaterThan(0);
|
|
@@ -21,12 +21,15 @@ describe('Job details fetch from SR API Tests', () => {
|
|
|
21
21
|
const fetchPositionsRequestBody = `fetchPositionsFromSRAPI();`;
|
|
22
22
|
const positions = await executeApiRequest(fetchPositionsRequestBody);
|
|
23
23
|
const randomPosition = getRandomPosition(positions.data.result.content);
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
console.log("
|
|
27
|
-
|
|
24
|
+
const fetchJobDescriptionRequestBody = `fetchJobDescription(${randomPosition.id});`;
|
|
25
|
+
const jobFetchResponse = await executeApiRequest(fetchJobDescriptionRequestBody);
|
|
26
|
+
console.log("jobFetchResponse: ", jobFetchResponse.data.result);
|
|
27
|
+
expect(jobFetchResponse.data.result.id).toBe(randomPosition.id);
|
|
28
|
+
expect(jobFetchResponse.data.result.jobAd.sections.jobDescription).toBeDefined();
|
|
29
|
+
expect(jobFetchResponse.data.result.jobAd.sections.jobDescription.text.length).toBeGreaterThan(0);
|
|
30
|
+
expect(jobFetchResponse.data.result.applyUrl.length).toBeGreaterThan(0);
|
|
31
|
+
expect(jobFetchResponse.data.result.location).toBeDefined();
|
|
28
32
|
});
|
|
29
33
|
|
|
30
34
|
|
|
31
|
-
|
|
32
35
|
});
|