sr-npm 1.7.560 → 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 +58 -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,11 +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 => {
|
|
88
|
+
|
|
86
89
|
const basicJob = {
|
|
87
90
|
_id: position.id,
|
|
88
91
|
title: position.name || '',
|
|
@@ -107,7 +110,7 @@ async function saveJobsDataToCMS() {
|
|
|
107
110
|
jobDescription: null, // Will be filled later
|
|
108
111
|
};
|
|
109
112
|
|
|
110
|
-
getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues
|
|
113
|
+
getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues);
|
|
111
114
|
return basicJob;
|
|
112
115
|
});
|
|
113
116
|
|
|
@@ -151,29 +154,31 @@ async function saveJobsDataToCMS() {
|
|
|
151
154
|
},
|
|
152
155
|
});
|
|
153
156
|
|
|
154
|
-
await insertValuesReference(jobToCustomValues);
|
|
155
|
-
console.log("inserted values reference successfully");
|
|
156
|
-
//await insertJobsReference(customValuesToJobs);
|
|
157
|
-
console.log("inserted jobs reference successfully");
|
|
157
|
+
// await insertValuesReference(jobToCustomValues);
|
|
158
|
+
// console.log("inserted values reference successfully");
|
|
159
|
+
// //await insertJobsReference(customValuesToJobs);
|
|
160
|
+
// console.log("inserted jobs reference successfully");
|
|
158
161
|
|
|
159
162
|
console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
|
|
160
163
|
}
|
|
161
164
|
|
|
162
|
-
async function insertValuesReference(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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");
|
|
169
173
|
}
|
|
170
|
-
async function insertJobsReference(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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");
|
|
177
182
|
}
|
|
178
183
|
|
|
179
184
|
async function populateCustomFieldsCollection(customFields) {
|
|
@@ -194,17 +199,23 @@ async function populateCustomValuesCollection(customFieldsValues) {
|
|
|
194
199
|
valuesToinsert.push({
|
|
195
200
|
_id: valueId,
|
|
196
201
|
title: valuesMap[valueId],
|
|
197
|
-
customField: fieldId,
|
|
202
|
+
customField: fieldId,
|
|
198
203
|
})
|
|
199
204
|
}
|
|
200
205
|
}
|
|
201
206
|
await wixData.bulkSave(COLLECTIONS.CUSTOM_VALUES, valuesToinsert);
|
|
202
207
|
}
|
|
203
|
-
async function
|
|
208
|
+
async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS() {
|
|
204
209
|
console.log('🚀 Starting job descriptions update process for ALL jobs');
|
|
205
210
|
|
|
206
211
|
try {
|
|
207
212
|
let jobsWithNoDescriptions = await getJobsWithNoDescriptions();
|
|
213
|
+
let customValues=await getAllCustomValues();
|
|
214
|
+
for (const valueId of customValues.items) {
|
|
215
|
+
await insertJobsReference(valueId);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
208
219
|
let totalUpdated = 0;
|
|
209
220
|
let totalFailed = 0;
|
|
210
221
|
let totalProcessed = 0;
|
|
@@ -233,7 +244,7 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
|
|
|
233
244
|
const jobLocation = fetchJobLocation(jobDetails);
|
|
234
245
|
const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
|
|
235
246
|
|
|
236
|
-
|
|
247
|
+
|
|
237
248
|
const updatedJob = {
|
|
238
249
|
...job,
|
|
239
250
|
locationAddress: jobLocation,
|
|
@@ -242,6 +253,7 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
|
|
|
242
253
|
referFriendLink: referFriendLink,
|
|
243
254
|
};
|
|
244
255
|
await wixData.update(COLLECTIONS.JOBS, updatedJob);
|
|
256
|
+
await insertValuesReference(job._id);
|
|
245
257
|
return { success: true, jobId: job._id, title: job.title };
|
|
246
258
|
} catch (error) {
|
|
247
259
|
console.error(` ❌ Failed to update ${job.title} (${job._id}):`, error);
|
|
@@ -313,7 +325,10 @@ async function aggregateJobsByFieldToCMS({ field, collection }) {
|
|
|
313
325
|
return { success: false, error: err.message };
|
|
314
326
|
}
|
|
315
327
|
}
|
|
316
|
-
|
|
328
|
+
async function getAllCustomValues() {
|
|
329
|
+
let customValuesQuery = await wixData.query(COLLECTIONS.CUSTOM_VALUES).limit(1000).find();
|
|
330
|
+
return customValuesQuery;
|
|
331
|
+
}
|
|
317
332
|
async function getJobsWithNoDescriptions() {
|
|
318
333
|
let jobswithoutdescriptionsQuery = await wixData
|
|
319
334
|
.query(COLLECTIONS.JOBS)
|
|
@@ -441,7 +456,22 @@ async function syncJobsFast() {
|
|
|
441
456
|
await saveJobsDataToCMS();
|
|
442
457
|
console.log("saved jobs data to CMS successfully");
|
|
443
458
|
console.log("saving jobs descriptions and location apply url to CMS");
|
|
444
|
-
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();
|
|
445
475
|
console.log("saved jobs descriptions and location apply url to CMS successfully");
|
|
446
476
|
await aggregateJobs();
|
|
447
477
|
await referenceJobs();
|
|
@@ -505,7 +535,7 @@ module.exports = {
|
|
|
505
535
|
aggregateJobs,
|
|
506
536
|
createCollections,
|
|
507
537
|
saveJobsDataToCMS,
|
|
508
|
-
saveJobsDescriptionsAndLocationApplyUrlToCMS,
|
|
538
|
+
saveJobsDescriptionsAndLocationApplyUrlToCMS: saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS,
|
|
509
539
|
aggregateJobsByFieldToCMS,
|
|
510
540
|
referenceJobsToField,
|
|
511
541
|
fillSecretManagerMirror,
|