sr-npm 1.7.475 → 1.7.477
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 +13 -1
- package/backend/data.js +15 -4
- package/backend/utils.js +10 -17
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ const COLLECTIONS = {
|
|
|
4
4
|
JOBS: 'Jobs',
|
|
5
5
|
TEMPLATE_TYPE: 'templateType',
|
|
6
6
|
SECRET_MANAGER_MIRROR: 'SecretManagerMirror',
|
|
7
|
+
BRANDS: 'Brands',
|
|
7
8
|
}
|
|
8
9
|
const JOBS_COLLECTION_FIELDS = {
|
|
9
10
|
LOCATION: 'location',
|
|
@@ -20,12 +21,17 @@ const JOBS_COLLECTION_FIELDS = {
|
|
|
20
21
|
IMAGE: 'image',
|
|
21
22
|
APPLY_LINK: 'applyLink',
|
|
22
23
|
REFER_FRIEND_LINK: 'referFriendLink',
|
|
24
|
+
BRAND: 'brand',
|
|
25
|
+
BRAND_REF: 'brandRef',
|
|
23
26
|
}
|
|
24
27
|
const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
|
|
25
28
|
TITLE: 'title',
|
|
26
29
|
COUNT: 'count',
|
|
27
30
|
IMAGE: 'image',
|
|
28
31
|
}
|
|
32
|
+
const BRANDS_COLLECTION_FIELDS = {
|
|
33
|
+
BRAND: 'brand',
|
|
34
|
+
}
|
|
29
35
|
const CITIES_COLLECTION_FIELDS = {
|
|
30
36
|
TITLE: 'title',
|
|
31
37
|
CITY: 'city',
|
|
@@ -57,9 +63,11 @@ const COLLECTIONS_FIELDS = {
|
|
|
57
63
|
{key:'jobDescription', type: 'OBJECT'},
|
|
58
64
|
{key:'cityText', type: 'TEXT'},
|
|
59
65
|
{key:'applyLink', type: 'URL'},
|
|
60
|
-
{key:'referFriendLink', type: 'URL'},
|
|
66
|
+
{key:'referFriendLink', type: 'URL'},
|
|
67
|
+
{key:'brand', type: 'TEXT'},
|
|
61
68
|
{key:'departmentref', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT } } },
|
|
62
69
|
{key:'city', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CITIES } } },
|
|
70
|
+
{key:'brandRef', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.BRANDS } } },
|
|
63
71
|
{ key: 'image', type: 'IMAGE' },
|
|
64
72
|
],
|
|
65
73
|
TEMPLATE_TYPE: [
|
|
@@ -69,6 +77,9 @@ const COLLECTIONS_FIELDS = {
|
|
|
69
77
|
{key:'tokenName', type: 'TEXT'},
|
|
70
78
|
{key:'tokenValue', type: 'TEXT'},
|
|
71
79
|
],
|
|
80
|
+
BRANDS: [
|
|
81
|
+
{key:'brand', type: 'TEXT'},
|
|
82
|
+
],
|
|
72
83
|
};
|
|
73
84
|
|
|
74
85
|
const TEMPLATE_TYPE = {
|
|
@@ -89,6 +100,7 @@ const COLLECTIONS_FIELDS = {
|
|
|
89
100
|
JOBS_COLLECTION_FIELDS,
|
|
90
101
|
AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS,
|
|
91
102
|
CITIES_COLLECTION_FIELDS,
|
|
103
|
+
BRANDS_COLLECTION_FIELDS,
|
|
92
104
|
TEMPLATE_TYPE,
|
|
93
105
|
TOKEN_NAME,
|
|
94
106
|
};
|
package/backend/data.js
CHANGED
|
@@ -2,10 +2,17 @@ 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,TEMPLATE_TYPE,TOKEN_NAME } = require('./collectionConsts');
|
|
5
|
-
const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,
|
|
5
|
+
const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeString} = require('./utils');
|
|
6
6
|
const { getAllPositions } = require('./queries');
|
|
7
7
|
const { getCompanyId, getSmartToken } = require('./secretsData');
|
|
8
8
|
|
|
9
|
+
function getBrand(customField) {
|
|
10
|
+
const brand = customField.find(field => field.fieldLabel === 'Brands')?.valueLabel;
|
|
11
|
+
console.log("brand: ", brand);
|
|
12
|
+
console.log("normalizeString(brand): ", normalizeString(brand));
|
|
13
|
+
return brand ? normalizeString(brand) : '';
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
function validatePosition(position) {
|
|
10
17
|
if (!position.id) {
|
|
11
18
|
throw new Error('Position id is required');
|
|
@@ -30,7 +37,7 @@ async function saveJobsDataToCMS() {
|
|
|
30
37
|
_id: position.id,
|
|
31
38
|
title: position.name || '',
|
|
32
39
|
department: position.department?.label || 'Other',
|
|
33
|
-
cityText:
|
|
40
|
+
cityText: normalizeString(position.location?.city).trim(),
|
|
34
41
|
location: position.location && Object.keys(position.location).length > 0
|
|
35
42
|
? position.location
|
|
36
43
|
: {
|
|
@@ -46,6 +53,7 @@ async function saveJobsDataToCMS() {
|
|
|
46
53
|
country: position.location?.country || '',
|
|
47
54
|
remote: position.location?.remote || false,
|
|
48
55
|
language: position.language?.label || '',
|
|
56
|
+
brand: getBrand(position.customField),
|
|
49
57
|
jobDescription: null, // Will be filled later
|
|
50
58
|
};
|
|
51
59
|
return basicJob;
|
|
@@ -294,7 +302,8 @@ async function createCollections() {
|
|
|
294
302
|
[createCollectionIfMissing(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.JOBS,{ insert: 'ADMIN', update: 'ADMIN', remove: 'ADMIN', read: 'ANYONE' }),
|
|
295
303
|
createCollectionIfMissing(COLLECTIONS.CITIES, COLLECTIONS_FIELDS.CITIES),
|
|
296
304
|
createCollectionIfMissing(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, COLLECTIONS_FIELDS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
|
|
297
|
-
createCollectionIfMissing(COLLECTIONS.SECRET_MANAGER_MIRROR, COLLECTIONS_FIELDS.SECRET_MANAGER_MIRROR)
|
|
305
|
+
createCollectionIfMissing(COLLECTIONS.SECRET_MANAGER_MIRROR, COLLECTIONS_FIELDS.SECRET_MANAGER_MIRROR),
|
|
306
|
+
createCollectionIfMissing(COLLECTIONS.BRANDS, COLLECTIONS_FIELDS.BRANDS)
|
|
298
307
|
]);
|
|
299
308
|
console.log("finished creating Collections");
|
|
300
309
|
}
|
|
@@ -303,7 +312,8 @@ async function aggregateJobs() {
|
|
|
303
312
|
console.log("Aggregating jobs");
|
|
304
313
|
await Promise.all([
|
|
305
314
|
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.DEPARTMENT, collection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT }),
|
|
306
|
-
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.CITY_TEXT, collection: COLLECTIONS.CITIES })
|
|
315
|
+
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.CITY_TEXT, collection: COLLECTIONS.CITIES }),
|
|
316
|
+
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.BRAND, collection: COLLECTIONS.BRANDS })
|
|
307
317
|
]);
|
|
308
318
|
console.log("finished aggregating jobs");
|
|
309
319
|
}
|
|
@@ -312,6 +322,7 @@ async function referenceJobs() {
|
|
|
312
322
|
console.log("Reference jobs");
|
|
313
323
|
await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.DEPARTMENT_REF, sourceCollection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, jobField: JOBS_COLLECTION_FIELDS.DEPARTMENT });
|
|
314
324
|
await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.CITY, sourceCollection: COLLECTIONS.CITIES, jobField: JOBS_COLLECTION_FIELDS.CITY_TEXT });
|
|
325
|
+
await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.BRAND_REF, sourceCollection: COLLECTIONS.BRANDS, jobField: JOBS_COLLECTION_FIELDS.BRAND });
|
|
315
326
|
console.log("finished referencing jobs");
|
|
316
327
|
}
|
|
317
328
|
|
package/backend/utils.js
CHANGED
|
@@ -35,7 +35,7 @@ function prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddre
|
|
|
35
35
|
return Object.entries(jobsPerField).map(([value, amount]) => {
|
|
36
36
|
const loc = cityLocations[value] || {};
|
|
37
37
|
const locAddress = citylocationAddress[value] || {};
|
|
38
|
-
value =
|
|
38
|
+
value = normalizeString(value).trim();
|
|
39
39
|
return {
|
|
40
40
|
title: value,
|
|
41
41
|
_id: value.replace(/\s+/g, ''),
|
|
@@ -48,29 +48,22 @@ function prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddre
|
|
|
48
48
|
} else {
|
|
49
49
|
return Object.entries(jobsPerField).map(([value, amount]) => ({
|
|
50
50
|
title: value,
|
|
51
|
-
_id:
|
|
51
|
+
_id: normalizeString(value).replace(/&/g, 'and'),
|
|
52
52
|
count: amount,
|
|
53
53
|
}));
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function
|
|
58
|
-
if (!
|
|
59
|
-
// Remove accents/diacritics, trim whitespace
|
|
60
|
-
return
|
|
57
|
+
function normalizeString(str) {
|
|
58
|
+
if (!str) return str;
|
|
59
|
+
// Remove accents/diacritics, keep spaces, trim whitespace
|
|
60
|
+
return str
|
|
61
61
|
.normalize('NFD')
|
|
62
62
|
.replace(/\p{Diacritic}/gu, '')
|
|
63
|
-
.
|
|
63
|
+
.replace(/[^A-Za-z0-9-\s]/g, '');
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
if (!input) return '';
|
|
68
|
-
const withoutDiacritics = String(input)
|
|
69
|
-
.normalize('NFD')
|
|
70
|
-
.replace(/\p{Diacritic}/gu, '');
|
|
71
|
-
const withAnd = withoutDiacritics.replace(/&/g, 'and');
|
|
72
|
-
return withAnd.replace(/[^A-Za-z0-9-]/g, '');
|
|
73
|
-
}
|
|
66
|
+
|
|
74
67
|
|
|
75
68
|
module.exports = {
|
|
76
69
|
chunkedBulkOperation,
|
|
@@ -78,6 +71,6 @@ module.exports = {
|
|
|
78
71
|
countJobsPerGivenField,
|
|
79
72
|
fillCityLocationAndLocationAddress,
|
|
80
73
|
prepareToSaveArray,
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
normalizeString,
|
|
75
|
+
|
|
83
76
|
};
|