sr-npm 1.7.63 → 1.7.64
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.
- package/backend/collectionConsts.js +6 -10
- package/backend/consts.js +7 -7
- package/backend/data.js +7 -6
- package/backend/fetchPositionsFromSRAPI.js +1 -1
- package/backend/utils.js +9 -14
- package/package.json +1 -1
|
@@ -9,27 +9,24 @@ const COLLECTIONS_FIELDS = {
|
|
|
9
9
|
AMOUNT_OF_JOBS_PER_DEPARTMENT: [
|
|
10
10
|
{key:'title', type: 'TEXT'},
|
|
11
11
|
{ key: 'count', type: 'NUMBER' },
|
|
12
|
+
{ key: 'image', type: 'IMAGE' },
|
|
12
13
|
],
|
|
13
14
|
CITIES: [
|
|
14
|
-
{key:'title', type: 'TEXT'},
|
|
15
|
-
{ key: 'regionCode', type: 'TEXT' },
|
|
15
|
+
{ key: 'title', type: 'TEXT' },
|
|
16
16
|
{ key: 'city', type: 'TEXT' },
|
|
17
|
-
{key:'
|
|
17
|
+
{key:'locationAddress', type: 'ADDRESS'},
|
|
18
18
|
{key:'count', type: 'NUMBER'},
|
|
19
19
|
{key:'country', type: 'TEXT'},
|
|
20
|
-
{key:'remote', type: 'TEXT'},
|
|
21
|
-
{key:'countryCode', type: 'TEXT'},
|
|
22
|
-
{key:'manual', type: 'TEXT'},
|
|
23
|
-
{key:'region', type: 'TEXT'},
|
|
24
|
-
{key:'latitude', type: 'NUMBER'},
|
|
25
|
-
{key:'longitude', type: 'NUMBER'},
|
|
26
20
|
],
|
|
27
21
|
JOBS: [
|
|
28
22
|
{key:'location', type: 'OBJECT'},
|
|
23
|
+
{key:'title', type: 'TEXT'},
|
|
24
|
+
{key:'locationAddress', type: 'ADDRESS'},
|
|
29
25
|
{key:'postingStatus', type: 'TEXT'},
|
|
30
26
|
{key:'country', type: 'TEXT'},
|
|
31
27
|
{key:'department', type: 'TEXT'},
|
|
32
28
|
{key:'language', type: 'TEXT'},
|
|
29
|
+
{key:'remote', type: 'BOOLEAN'},
|
|
33
30
|
{key:'jobDescription', type: 'OBJECT'},
|
|
34
31
|
{key:'cityText', type: 'TEXT'},
|
|
35
32
|
{key:'departmentRef', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: 'AmountOfJobsPerDepartment1' } } },
|
|
@@ -41,7 +38,6 @@ const COLLECTIONS_FIELDS = {
|
|
|
41
38
|
};
|
|
42
39
|
|
|
43
40
|
|
|
44
|
-
|
|
45
41
|
module.exports = {
|
|
46
42
|
COLLECTIONS,
|
|
47
43
|
COLLECTIONS_FIELDS,
|
package/backend/consts.js
CHANGED
|
@@ -45,7 +45,7 @@ const TASKS = {
|
|
|
45
45
|
[TASKS_NAMES.CREATE_JOBS_COLLECTION]: {
|
|
46
46
|
name: TASKS_NAMES.CREATE_JOBS_COLLECTION,
|
|
47
47
|
getIdentifier: () => 'SHOULD_NEVER_SKIP',
|
|
48
|
-
process: () => createCollectionIfMissing(COLLECTIONS.JOBS, COLLECTIONS_FIELDS.JOBS),
|
|
48
|
+
process: () => createCollectionIfMissing(COLLECTIONS.JOBS, COLLECTIONS_FIELDS.JOBS,{ insert: 'ADMIN', update: 'ADMIN', remove: 'ADMIN', read: 'ANYONE' }),
|
|
49
49
|
shouldSkipCheck: () => false,
|
|
50
50
|
estimatedDurationSec: 3,
|
|
51
51
|
},
|
|
@@ -86,7 +86,7 @@ const TASKS = {
|
|
|
86
86
|
getIdentifier: () => 'SHOULD_NEVER_SKIP',
|
|
87
87
|
process: () =>
|
|
88
88
|
aggregateJobsByFieldToCMS({
|
|
89
|
-
field: COLLECTIONS_FIELDS.JOBS[
|
|
89
|
+
field: COLLECTIONS_FIELDS.JOBS[9].key,
|
|
90
90
|
collection: COLLECTIONS.CITIES,
|
|
91
91
|
}),
|
|
92
92
|
shouldSkipCheck: () => false,
|
|
@@ -97,7 +97,7 @@ const TASKS = {
|
|
|
97
97
|
getIdentifier: () => 'SHOULD_NEVER_SKIP',
|
|
98
98
|
process: () =>
|
|
99
99
|
aggregateJobsByFieldToCMS({
|
|
100
|
-
field: COLLECTIONS_FIELDS.JOBS[
|
|
100
|
+
field: COLLECTIONS_FIELDS.JOBS[5].key,
|
|
101
101
|
collection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT,
|
|
102
102
|
}),
|
|
103
103
|
shouldSkipCheck: () => false,
|
|
@@ -108,9 +108,9 @@ const TASKS = {
|
|
|
108
108
|
getIdentifier: () => 'SHOULD_NEVER_SKIP',
|
|
109
109
|
process: () =>
|
|
110
110
|
referenceJobsToField({
|
|
111
|
-
referenceField: COLLECTIONS_FIELDS.JOBS[
|
|
111
|
+
referenceField: COLLECTIONS_FIELDS.JOBS[11].key,
|
|
112
112
|
sourceCollection: COLLECTIONS.CITIES,
|
|
113
|
-
jobField: COLLECTIONS_FIELDS.JOBS[
|
|
113
|
+
jobField: COLLECTIONS_FIELDS.JOBS[9].key,
|
|
114
114
|
}),
|
|
115
115
|
shouldSkipCheck: () => false,
|
|
116
116
|
estimatedDurationSec: 3,
|
|
@@ -120,9 +120,9 @@ const TASKS = {
|
|
|
120
120
|
getIdentifier: () => 'SHOULD_NEVER_SKIP',
|
|
121
121
|
process: () =>
|
|
122
122
|
referenceJobsToField({
|
|
123
|
-
referenceField: COLLECTIONS_FIELDS.JOBS[
|
|
123
|
+
referenceField: COLLECTIONS_FIELDS.JOBS[10].key,
|
|
124
124
|
sourceCollection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT,
|
|
125
|
-
jobField: COLLECTIONS_FIELDS.JOBS[
|
|
125
|
+
jobField: COLLECTIONS_FIELDS.JOBS[5].key,
|
|
126
126
|
}),
|
|
127
127
|
shouldSkipCheck: () => false,
|
|
128
128
|
estimatedDurationSec: 3,
|
package/backend/data.js
CHANGED
|
@@ -4,7 +4,7 @@ const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend
|
|
|
4
4
|
const { COLLECTIONS, COLLECTIONS_FIELDS } = require('./collectionConsts');
|
|
5
5
|
const { secrets } = require("@wix/secrets");
|
|
6
6
|
const { auth } = require('@wix/essentials');
|
|
7
|
-
const { chunkedBulkOperation, delay, countJobsPerGivenField,
|
|
7
|
+
const { chunkedBulkOperation, delay, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeCityName} = require('./utils');
|
|
8
8
|
const { getAllPositions } = require('./queries');
|
|
9
9
|
|
|
10
10
|
|
|
@@ -143,18 +143,19 @@ async function saveJobsDescriptionsAndLocationToCMS() {
|
|
|
143
143
|
function iterateOverAllJobs(results, field) {
|
|
144
144
|
const jobsPerField = {};
|
|
145
145
|
const cityLocations = {};
|
|
146
|
+
const citylocationAddress = {};
|
|
146
147
|
countJobsPerGivenField(results, field, jobsPerField);
|
|
147
148
|
if (field === 'cityText') {
|
|
148
|
-
|
|
149
|
+
fillCityLocationAndLocationAddress(results, cityLocations,citylocationAddress);
|
|
149
150
|
}
|
|
150
|
-
return { jobsPerField, cityLocations };
|
|
151
|
+
return { jobsPerField, cityLocations,citylocationAddress };
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
async function aggregateJobsByFieldToCMS({ field, collection }) {
|
|
154
155
|
console.log(`counting jobs per ${field}.`);
|
|
155
156
|
let results = await getAllPositions();
|
|
156
|
-
const { jobsPerField, cityLocations } = iterateOverAllJobs(results, field);
|
|
157
|
-
const toSave =
|
|
157
|
+
const { jobsPerField, cityLocations,citylocationAddress } = iterateOverAllJobs(results, field);
|
|
158
|
+
const toSave = prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddress);
|
|
158
159
|
if (toSave.length === 0) {
|
|
159
160
|
console.log('No jobs found.');
|
|
160
161
|
return { success: true, message: 'No jobs to save.' };
|
|
@@ -253,7 +254,6 @@ function fetchJobLocation(jobDetails) {
|
|
|
253
254
|
}
|
|
254
255
|
|
|
255
256
|
|
|
256
|
-
|
|
257
257
|
function getSmartToken() {
|
|
258
258
|
const elevatedGetSecretValue = auth.elevate(secrets.getSecretValue);
|
|
259
259
|
return elevatedGetSecretValue("x-smarttoken")
|
|
@@ -262,6 +262,7 @@ function getSmartToken() {
|
|
|
262
262
|
})
|
|
263
263
|
.catch((error) => {
|
|
264
264
|
console.error(error);
|
|
265
|
+
throw error;
|
|
265
266
|
});
|
|
266
267
|
}
|
|
267
268
|
|
|
@@ -116,7 +116,7 @@ async function getSmartTokenFromCMS() {
|
|
|
116
116
|
if (result.items.length > 0) {
|
|
117
117
|
return result.items[0].token; // This is your string token
|
|
118
118
|
} else {
|
|
119
|
-
|
|
119
|
+
throw new Error('[getSmartTokenFromCMS], No token found');
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
package/backend/utils.js
CHANGED
|
@@ -18,34 +18,29 @@ function countJobsPerGivenField(jobs, field,jobsPerField) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function
|
|
21
|
+
function fillCityLocationAndLocationAddress(jobs, cityLocations,citylocationAddress) {
|
|
22
22
|
for (const job of jobs) {
|
|
23
|
-
if (!cityLocations[job.cityText]) {
|
|
23
|
+
if (!cityLocations[job.cityText] && !citylocationAddress[job.cityText]) {
|
|
24
24
|
cityLocations[job.cityText] = job.location;
|
|
25
|
+
citylocationAddress[job.cityText] = job.locationAddress;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
function prepareToSaveArray(jobsPerField, cityLocations, field) {
|
|
30
|
+
function prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddress) {
|
|
30
31
|
if (field === 'cityText') {
|
|
31
32
|
return Object.entries(jobsPerField).map(([value, amount]) => {
|
|
32
33
|
const loc = cityLocations[value] || {};
|
|
34
|
+
const locAddress = citylocationAddress[value] || {};
|
|
33
35
|
value = normalizeCityName(value);
|
|
34
36
|
return {
|
|
35
37
|
title: value,
|
|
36
38
|
_id: value.replace(/\s+/g, ''),
|
|
37
39
|
count: amount,
|
|
38
|
-
|
|
39
|
-
countryCode: loc.countryCode,
|
|
40
|
+
locationAddress: locAddress,
|
|
40
41
|
country: loc.country,
|
|
41
|
-
region: loc.region,
|
|
42
42
|
city: loc.city,
|
|
43
|
-
|
|
44
|
-
remote: loc.remote.toString(),
|
|
45
|
-
regionCode: loc.regionCode,
|
|
46
|
-
latitude: loc.latitude,
|
|
47
|
-
longitude: loc.longitude,
|
|
48
|
-
};
|
|
43
|
+
};
|
|
49
44
|
});
|
|
50
45
|
} else {
|
|
51
46
|
return Object.entries(jobsPerField).map(([value, amount]) => ({
|
|
@@ -69,7 +64,7 @@ module.exports = {
|
|
|
69
64
|
chunkedBulkOperation,
|
|
70
65
|
delay,
|
|
71
66
|
countJobsPerGivenField,
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
fillCityLocationAndLocationAddress,
|
|
68
|
+
prepareToSaveArray,
|
|
74
69
|
normalizeCityName,
|
|
75
70
|
};
|