sr-npm 1.7.561 → 1.7.562
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/consts.js +13 -0
- package/backend/data.js +55 -28
- package/package.json +1 -1
package/backend/consts.js
CHANGED
|
@@ -5,6 +5,7 @@ const QUERY_MAX_LIMIT = 1000;
|
|
|
5
5
|
|
|
6
6
|
const TASKS_NAMES = {
|
|
7
7
|
SYNC_JOBS: 'syncJobsFromSRAPIToCMS',
|
|
8
|
+
SYNC_JOBS_SPLITTED: 'syncJobsFromSRAPIToCMSSplitted',
|
|
8
9
|
INSERT_JOBS_TO_CMS: 'insertJobsToCMS',
|
|
9
10
|
INSERT_JOBS_DESCRIPTIONS_LOCATION_APPLY_URL_TO_CMS: 'insertJobsDescriptionsLocationApplyUrlToCMS',
|
|
10
11
|
AGGREGATE_JOBS_BY_FIELD_TO_CMS: 'aggregateJobsByFieldToCMS',
|
|
@@ -28,6 +29,18 @@ const TASKS = {
|
|
|
28
29
|
scheduleChildrenSequentially: true,
|
|
29
30
|
estimatedDurationSec: 60,
|
|
30
31
|
},
|
|
32
|
+
[TASKS_NAMES.SYNC_JOBS_SPLITTED]: {
|
|
33
|
+
name: TASKS_NAMES.SYNC_JOBS_SPLITTED,
|
|
34
|
+
childTasks: [
|
|
35
|
+
{ name: TASKS_NAMES.CREATE_COLLECTIONS},
|
|
36
|
+
{ name: TASKS_NAMES.INSERT_JOBS_TO_CMS },
|
|
37
|
+
{ name: TASKS_NAMES.INSERT_JOBS_DESCRIPTIONS_LOCATION_APPLY_URL_TO_CMS },
|
|
38
|
+
{ name: TASKS_NAMES.AGGREGATE_JOBS_BY_FIELD_TO_CMS },
|
|
39
|
+
{name: TASKS_NAMES.REFERENCE_JOBS},
|
|
40
|
+
],
|
|
41
|
+
scheduleChildrenSequentially: true,
|
|
42
|
+
estimatedDurationSec: 60,
|
|
43
|
+
},
|
|
31
44
|
[TASKS_NAMES.CREATE_COLLECTIONS]: {
|
|
32
45
|
name: TASKS_NAMES.CREATE_COLLECTIONS,
|
|
33
46
|
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
package/backend/data.js
CHANGED
|
@@ -6,6 +6,10 @@ const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocatio
|
|
|
6
6
|
const { getAllPositions } = require('./queries');
|
|
7
7
|
const { retrieveSecretVal, getTokenFromCMS } = require('./secretsData');
|
|
8
8
|
|
|
9
|
+
|
|
10
|
+
let jobToCustomValues = {}
|
|
11
|
+
let customValuesToJobs = {}
|
|
12
|
+
|
|
9
13
|
function getBrand(customField) {
|
|
10
14
|
return customField.find(field => field.fieldLabel === 'Brands')?.valueLabel;
|
|
11
15
|
}
|
|
@@ -52,7 +56,7 @@ function validateSingleDesiredBrand(desiredBrand) {
|
|
|
52
56
|
throw new Error("Desired brand must be a single brand");
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
|
-
function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues
|
|
59
|
+
function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues) {
|
|
56
60
|
const customFieldsArray = Array.isArray(position?.customField) ? position.customField : [];
|
|
57
61
|
for (const field of customFieldsArray) {
|
|
58
62
|
if(field.fieldLabel==="Country" || field.fieldLabel==="Department" || field.fieldLabel==="Brands") continue; //country and department are not custom fields, they are already in the job object
|
|
@@ -78,12 +82,10 @@ async function saveJobsDataToCMS() {
|
|
|
78
82
|
const sourcePositions = await filterBasedOnBrand(positions);
|
|
79
83
|
const customFieldsLabels = {}
|
|
80
84
|
const customFieldsValues = {}
|
|
81
|
-
const jobToCustomValues = {}
|
|
82
|
-
const customValuesToJobs = {}
|
|
83
85
|
|
|
84
86
|
// bulk insert to jobs collection without descriptions first
|
|
85
87
|
const jobsData = sourcePositions.map(position => {
|
|
86
|
-
|
|
88
|
+
|
|
87
89
|
const basicJob = {
|
|
88
90
|
_id: position.id,
|
|
89
91
|
title: position.name || '',
|
|
@@ -106,10 +108,9 @@ async function saveJobsDataToCMS() {
|
|
|
106
108
|
language: position.language?.label || '',
|
|
107
109
|
brand: getBrand(position.customField),
|
|
108
110
|
jobDescription: null, // Will be filled later
|
|
109
|
-
multiRefJobsCustomValues: jobToCustomValues[position.id],
|
|
110
111
|
};
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues);
|
|
113
114
|
return basicJob;
|
|
114
115
|
});
|
|
115
116
|
|
|
@@ -117,7 +118,7 @@ async function saveJobsDataToCMS() {
|
|
|
117
118
|
console.log("customFieldsValues: ", customFieldsValues);
|
|
118
119
|
console.log("jobToCustomValues: ", jobToCustomValues);
|
|
119
120
|
await populateCustomFieldsCollection(customFieldsLabels);
|
|
120
|
-
await populateCustomValuesCollection(customFieldsValues
|
|
121
|
+
await populateCustomValuesCollection(customFieldsValues);
|
|
121
122
|
// Sort jobs by title (ascending, case-insensitive, numeric-aware)
|
|
122
123
|
jobsData.sort((a, b) => {
|
|
123
124
|
const titleA = a.title || '';
|
|
@@ -161,21 +162,23 @@ async function saveJobsDataToCMS() {
|
|
|
161
162
|
console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
|
|
162
163
|
}
|
|
163
164
|
|
|
164
|
-
async function insertValuesReference(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
async function insertValuesReference(jobId) {
|
|
166
|
+
await wixData.insertReference(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,jobId, jobToCustomValues[jobId]);
|
|
167
|
+
// console.log("inserting values reference");
|
|
168
|
+
// for (const jobId of Object.keys(jobToCustomValues)) {
|
|
169
|
+
// const items = jobToCustomValues[jobId];
|
|
170
|
+
// await wixData.insertReference(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,jobId, items);
|
|
171
|
+
// }
|
|
172
|
+
// console.log("inserted values reference successfully");
|
|
171
173
|
}
|
|
172
|
-
async function insertJobsReference(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
async function insertJobsReference(valueId) {
|
|
175
|
+
await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,valueId, customValuesToJobs[valueId]);
|
|
176
|
+
// console.log("inserting jobs reference");
|
|
177
|
+
// for (const valueId of Object.keys(customValuesToJobs)) {
|
|
178
|
+
// const items = customValuesToJobs[valueId];
|
|
179
|
+
// await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,valueId, items);
|
|
180
|
+
// }
|
|
181
|
+
// console.log("inserted jobs reference successfully");
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
async function populateCustomFieldsCollection(customFields) {
|
|
@@ -188,7 +191,7 @@ async function populateCustomFieldsCollection(customFields) {
|
|
|
188
191
|
}
|
|
189
192
|
await wixData.bulkSave(COLLECTIONS.CUSTOM_FIELDS, fieldstoinsert);
|
|
190
193
|
}
|
|
191
|
-
async function populateCustomValuesCollection(customFieldsValues
|
|
194
|
+
async function populateCustomValuesCollection(customFieldsValues) {
|
|
192
195
|
valuesToinsert=[]
|
|
193
196
|
for (const fieldId of Object.keys(customFieldsValues)) {
|
|
194
197
|
const valuesMap = customFieldsValues[fieldId] || {};
|
|
@@ -197,17 +200,22 @@ async function populateCustomValuesCollection(customFieldsValues,customValuesToJ
|
|
|
197
200
|
_id: valueId,
|
|
198
201
|
title: valuesMap[valueId],
|
|
199
202
|
customField: fieldId,
|
|
200
|
-
multiRefJobsCustomValues: customValuesToJobs[valueId], // reference to CustomFields collection (displays the label)
|
|
201
203
|
})
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
206
|
await wixData.bulkSave(COLLECTIONS.CUSTOM_VALUES, valuesToinsert);
|
|
205
207
|
}
|
|
206
|
-
async function
|
|
208
|
+
async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
|
|
207
209
|
console.log('🚀 Starting job descriptions update process for ALL jobs');
|
|
208
210
|
|
|
209
211
|
try {
|
|
210
212
|
let jobsWithNoDescriptions = await getJobsWithNoDescriptions();
|
|
213
|
+
let customValues=await getAllCustomValues();
|
|
214
|
+
for (const valueId of customValues.items) {
|
|
215
|
+
await insertJobsReference(valueId);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
211
219
|
let totalUpdated = 0;
|
|
212
220
|
let totalFailed = 0;
|
|
213
221
|
let totalProcessed = 0;
|
|
@@ -236,7 +244,7 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
|
|
|
236
244
|
const jobLocation = fetchJobLocation(jobDetails);
|
|
237
245
|
const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
|
|
238
246
|
|
|
239
|
-
|
|
247
|
+
|
|
240
248
|
const updatedJob = {
|
|
241
249
|
...job,
|
|
242
250
|
locationAddress: jobLocation,
|
|
@@ -245,6 +253,7 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
|
|
|
245
253
|
referFriendLink: referFriendLink,
|
|
246
254
|
};
|
|
247
255
|
await wixData.update(COLLECTIONS.JOBS, updatedJob);
|
|
256
|
+
await insertValuesReference(job._id);
|
|
248
257
|
return { success: true, jobId: job._id, title: job.title };
|
|
249
258
|
} catch (error) {
|
|
250
259
|
console.error(` ❌ Failed to update ${job.title} (${job._id}):`, error);
|
|
@@ -316,7 +325,10 @@ async function aggregateJobsByFieldToCMS({ field, collection }) {
|
|
|
316
325
|
return { success: false, error: err.message };
|
|
317
326
|
}
|
|
318
327
|
}
|
|
319
|
-
|
|
328
|
+
async function getAllCustomValues() {
|
|
329
|
+
let customValuesQuery = await wixData.query(COLLECTIONS.CUSTOM_VALUES).limit(1000).find();
|
|
330
|
+
return customValuesQuery;
|
|
331
|
+
}
|
|
320
332
|
async function getJobsWithNoDescriptions() {
|
|
321
333
|
let jobswithoutdescriptionsQuery = await wixData
|
|
322
334
|
.query(COLLECTIONS.JOBS)
|
|
@@ -444,7 +456,22 @@ async function syncJobsFast() {
|
|
|
444
456
|
await saveJobsDataToCMS();
|
|
445
457
|
console.log("saved jobs data to CMS successfully");
|
|
446
458
|
console.log("saving jobs descriptions and location apply url to CMS");
|
|
447
|
-
await
|
|
459
|
+
await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
|
|
460
|
+
console.log("saved jobs descriptions and location apply url to CMS successfully");
|
|
461
|
+
await aggregateJobs();
|
|
462
|
+
await referenceJobs();
|
|
463
|
+
console.log("syncing jobs fast finished successfully");
|
|
464
|
+
}
|
|
465
|
+
async function syncJobsFastSplitted() {
|
|
466
|
+
console.log("Syncing jobs fast");
|
|
467
|
+
await createCollections();
|
|
468
|
+
await clearCollections();
|
|
469
|
+
await fillSecretManagerMirror();
|
|
470
|
+
console.log("saving jobs data to CMS");
|
|
471
|
+
await saveJobsDataToCMS();
|
|
472
|
+
console.log("saved jobs data to CMS successfully");
|
|
473
|
+
console.log("saving jobs descriptions and location apply url to CMS");
|
|
474
|
+
await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
|
|
448
475
|
console.log("saved jobs descriptions and location apply url to CMS successfully");
|
|
449
476
|
await aggregateJobs();
|
|
450
477
|
await referenceJobs();
|
|
@@ -508,7 +535,7 @@ module.exports = {
|
|
|
508
535
|
aggregateJobs,
|
|
509
536
|
createCollections,
|
|
510
537
|
saveJobsDataToCMS,
|
|
511
|
-
saveJobsDescriptionsAndLocationApplyUrlToCMS,
|
|
538
|
+
saveJobsDescriptionsAndLocationApplyUrlToCMS: saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS,
|
|
512
539
|
aggregateJobsByFieldToCMS,
|
|
513
540
|
referenceJobsToField,
|
|
514
541
|
fillSecretManagerMirror,
|