sr-npm 1.7.1319 → 1.7.1321
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/data.js +43 -154
- package/package.json +1 -1
package/backend/data.js
CHANGED
|
@@ -114,7 +114,7 @@ function getCustomFieldsAndValuesFromPosition(position, customFieldsLabels, cust
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
async function
|
|
117
|
+
async function retrieveJobsData() {
|
|
118
118
|
const positions = await fetchPositionsFromSRAPI();
|
|
119
119
|
const sourcePositions = await filterBasedOnBrand(positions);
|
|
120
120
|
const customFieldsLabels = {}
|
|
@@ -165,6 +165,7 @@ async function saveJobsDataToCMS() {
|
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
if (siteconfig.customFields==="true") {
|
|
168
|
+
|
|
168
169
|
await populateCustomFieldsCollection(customFieldsLabels,templateType);
|
|
169
170
|
await populateCustomValuesCollection(customFieldsValues);
|
|
170
171
|
}
|
|
@@ -175,34 +176,6 @@ async function saveJobsDataToCMS() {
|
|
|
175
176
|
const titleB = b.title || '';
|
|
176
177
|
return titleA.localeCompare(titleB, undefined, { sensitivity: 'base', numeric: true });
|
|
177
178
|
});
|
|
178
|
-
|
|
179
|
-
// const chunkSize = 1000;
|
|
180
|
-
// let totalSaved = 0;
|
|
181
|
-
// const totalChunks = Math.ceil(jobsData.length / chunkSize);
|
|
182
|
-
|
|
183
|
-
// console.log(
|
|
184
|
-
// `Processing ${jobsData.length} jobs in ${totalChunks} chunks of max ${chunkSize} items each`
|
|
185
|
-
// );
|
|
186
|
-
|
|
187
|
-
// await chunkedBulkOperation({
|
|
188
|
-
// items: jobsData,
|
|
189
|
-
// chunkSize,
|
|
190
|
-
// processChunk: async (chunk, chunkNumber) => {
|
|
191
|
-
// console.log(`Saving chunk ${chunkNumber}/${totalChunks}: ${chunk.length} jobs`);
|
|
192
|
-
// try {
|
|
193
|
-
// const result = await wixData.bulkSave(COLLECTIONS.JOBS, chunk);
|
|
194
|
-
// const saved = result.inserted + result.updated || chunk.length;
|
|
195
|
-
// totalSaved += saved;
|
|
196
|
-
// console.log(
|
|
197
|
-
// `✓ Chunk ${chunkNumber} saved successfully. Inserted: ${result.inserted}, Updated: ${result.updated}`
|
|
198
|
-
// );
|
|
199
|
-
// } catch (error) {
|
|
200
|
-
// console.error(`✗ Error saving chunk ${chunkNumber}:`, error);
|
|
201
|
-
// throw error;
|
|
202
|
-
// }
|
|
203
|
-
// },
|
|
204
|
-
// });
|
|
205
|
-
// console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
|
|
206
179
|
return jobsData;
|
|
207
180
|
}
|
|
208
181
|
|
|
@@ -243,45 +216,14 @@ async function populateCustomValuesCollection(customFieldsValues) {
|
|
|
243
216
|
await wixData.bulkSave(COLLECTIONS.CUSTOM_VALUES, valuesToinsert);
|
|
244
217
|
}
|
|
245
218
|
|
|
246
|
-
async function
|
|
219
|
+
async function retrieveJobsDescriptionsAndLocationApplyUrlReferences(jobsWithNoDescriptions) {
|
|
247
220
|
console.log('🚀 Starting job descriptions update process for ALL jobs');
|
|
248
221
|
console.log("jobsWithNoDescriptions: ",jobsWithNoDescriptions);
|
|
249
222
|
|
|
250
223
|
try {
|
|
251
|
-
// let jobsWithNoDescriptions = await getJobsWithNoDescriptions();
|
|
252
|
-
|
|
253
|
-
// if (siteconfig.customFields==="true") {
|
|
254
|
-
// let customValues = await getAllCustomValues();
|
|
255
|
-
|
|
256
|
-
// console.log("inserting jobs references to custom values collection");
|
|
257
|
-
// console.log("customValues: ",customValues)
|
|
258
|
-
// console.log("customValues.items: ",customValues.items)
|
|
259
|
-
|
|
260
|
-
// for (const value of customValues.items) {
|
|
261
|
-
// await insertJobsReference(value._id, value.valueId);
|
|
262
|
-
// }
|
|
263
|
-
// console.log("inserted jobs references to custom values collection successfully");
|
|
264
|
-
// }
|
|
265
224
|
|
|
266
|
-
// let totalUpdated = 0;
|
|
267
|
-
// let totalFailed = 0;
|
|
268
|
-
// let totalProcessed = 0;
|
|
269
|
-
|
|
270
|
-
// console.log(
|
|
271
|
-
// `Total jobs in database without descriptions: ${jobsWithNoDescriptions?.length}`
|
|
272
|
-
// );
|
|
273
|
-
|
|
274
|
-
// if (jobsWithNoDescriptions.length === 0) {
|
|
275
|
-
// console.log('No jobs found in database');
|
|
276
|
-
// return { success: true, message: 'No jobs found' };
|
|
277
|
-
// }
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
// const API_CHUNK_SIZE = 80;
|
|
281
|
-
//const pageChunks = Math.ceil(jobsWithNoDescriptions.items.length / API_CHUNK_SIZE);
|
|
282
225
|
const richContentConverterToken = await getTokenFromCMS(TOKEN_NAME.RICH_CONTENT_CONVERTER_TOKEN);
|
|
283
226
|
|
|
284
|
-
console.log("before promise all")
|
|
285
227
|
const jobsWithDescriptions=await Promise.all(jobsWithNoDescriptions.map( async job => {
|
|
286
228
|
const jobDetails = await fetchJobDescription(job._id);
|
|
287
229
|
const richContentDescription= await htmlRichContentConverter(jobDetails.jobAd.sections,richContentConverterToken);
|
|
@@ -299,58 +241,6 @@ async function saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS(jobsWithNo
|
|
|
299
241
|
console.log("jobsWithDescriptions: after map ",jobsWithDescriptions);
|
|
300
242
|
return {success: true, updatedJobs: jobsWithDescriptions};
|
|
301
243
|
|
|
302
|
-
// await chunkedBulkOperation({
|
|
303
|
-
// items: jobsWithNoDescriptions.items,
|
|
304
|
-
// chunkSize: API_CHUNK_SIZE,
|
|
305
|
-
// processChunk: async (chunk, chunkNumber) => {
|
|
306
|
-
// console.log(` Processing API chunk ${chunkNumber}/${pageChunks} (${chunk.length} jobs)`);
|
|
307
|
-
// const chunkPromises = chunk.map(async job => {
|
|
308
|
-
// try {
|
|
309
|
-
// const jobDetails = await fetchJobDescription(job._id);
|
|
310
|
-
// const richContentDescription=await htmlRichContentConverter(jobDetails.jobAd.sections,richContentConverterToken);
|
|
311
|
-
// const jobLocation = fetchJobLocation(jobDetails);
|
|
312
|
-
// const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
|
|
313
|
-
// const updatedJob = {
|
|
314
|
-
// ...job,
|
|
315
|
-
// locationAddress: jobLocation,
|
|
316
|
-
// jobDescription: richContentDescription,
|
|
317
|
-
// applyLink: applyLink,
|
|
318
|
-
// referFriendLink: referFriendLink,
|
|
319
|
-
// };
|
|
320
|
-
// await wixData.update(COLLECTIONS.JOBS, updatedJob);
|
|
321
|
-
// return { success: true, jobId: job._id, title: job.title };
|
|
322
|
-
// } catch (error) {
|
|
323
|
-
// console.error(` ❌ Failed to update ${job.title} (${job._id}):`, error);
|
|
324
|
-
// return { success: false, jobId: job._id, title: job.title, error: error.message };
|
|
325
|
-
// }
|
|
326
|
-
// });
|
|
327
|
-
// const chunkResults = await Promise.all(chunkPromises);
|
|
328
|
-
// const chunkSuccesses = chunkResults.filter(r => r.success).length;
|
|
329
|
-
// const chunkFailures = chunkResults.filter(r => !r.success).length;
|
|
330
|
-
// totalUpdated += chunkSuccesses;
|
|
331
|
-
// totalFailed += chunkFailures;
|
|
332
|
-
// totalProcessed += chunk.length;
|
|
333
|
-
// console.log(
|
|
334
|
-
// ` API chunk ${chunkNumber} completed: ${chunkSuccesses} success, ${chunkFailures} failed`
|
|
335
|
-
// );
|
|
336
|
-
// },
|
|
337
|
-
// });
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
// console.log(`\n✅ Finished updating ALL job descriptions`);
|
|
342
|
-
// console.log(`📊 Final Results:`);
|
|
343
|
-
// console.log(` Total jobs processed: ${totalProcessed}`);
|
|
344
|
-
// console.log(` Total updated: ${totalUpdated}`);
|
|
345
|
-
// console.log(` Total failed: ${totalFailed}`);
|
|
346
|
-
|
|
347
|
-
// return {
|
|
348
|
-
// success: true,
|
|
349
|
-
// totalProcessed: totalProcessed,
|
|
350
|
-
// totalUpdated: totalUpdated,
|
|
351
|
-
// totalFailed: totalFailed,
|
|
352
|
-
// message: `Successfully updated ${totalUpdated} job descriptions out of ${totalProcessed} total jobs`,
|
|
353
|
-
// };
|
|
354
244
|
} catch (error) {
|
|
355
245
|
console.error('❌ Error in updateJobDescriptions:', error);
|
|
356
246
|
throw error;
|
|
@@ -395,14 +285,7 @@ async function getAllCustomValues() {
|
|
|
395
285
|
return customValuesQuery;
|
|
396
286
|
}
|
|
397
287
|
|
|
398
|
-
|
|
399
|
-
let jobswithoutdescriptionsQuery = await wixData
|
|
400
|
-
.query(COLLECTIONS.JOBS)
|
|
401
|
-
.limit(1000)
|
|
402
|
-
.isEmpty('jobDescription')
|
|
403
|
-
.find();
|
|
404
|
-
return jobswithoutdescriptionsQuery;
|
|
405
|
-
}
|
|
288
|
+
|
|
406
289
|
|
|
407
290
|
/**
|
|
408
291
|
* @param {Object} params
|
|
@@ -527,22 +410,46 @@ async function syncJobsFast() {
|
|
|
527
410
|
try{
|
|
528
411
|
console.log("Syncing jobs fast");
|
|
529
412
|
await createCollections();
|
|
530
|
-
|
|
413
|
+
await clearCollections();
|
|
531
414
|
await fillSecretManagerMirror();
|
|
532
415
|
|
|
533
|
-
console.log("
|
|
534
|
-
const jobsData = await
|
|
416
|
+
console.log("retrieving jobs data from SR API");
|
|
417
|
+
const jobsData = await retrieveJobsData();
|
|
535
418
|
console.log("jobsData inside syncJobsFast: ",jobsData);
|
|
536
|
-
console.log("
|
|
419
|
+
console.log("retrieved jobs data from SR API successfully");
|
|
537
420
|
|
|
538
|
-
console.log("
|
|
539
|
-
const status=await
|
|
421
|
+
console.log("retrieving jobs descriptions and location apply url from SR API");
|
|
422
|
+
const status=await retrieveJobsDescriptionsAndLocationApplyUrlReferences(jobsData);
|
|
540
423
|
|
|
541
424
|
console.log("status inside syncJobsFast: ",status);
|
|
542
425
|
if(status.success){
|
|
543
|
-
await
|
|
426
|
+
await wixData.truncate(COLLECTIONS.JOBS)
|
|
544
427
|
const updatedJobs=status.updatedJobs;
|
|
545
|
-
|
|
428
|
+
console.log("updatedJobs inside syncJobsFast: ",updatedJobs);
|
|
429
|
+
await saveJobsToCMS(updatedJobs);
|
|
430
|
+
console.log("saved jobs to CMS successfully");
|
|
431
|
+
|
|
432
|
+
if (siteconfig.customFields==="true") {
|
|
433
|
+
await insertJobsReferencesToCustomValuesCollection();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
console.log("saved jobs data, descriptions and location apply url to CMS successfully");
|
|
437
|
+
|
|
438
|
+
await aggregateJobs();
|
|
439
|
+
await referenceJobs();
|
|
440
|
+
|
|
441
|
+
console.log("syncing jobs fast finished successfully");
|
|
442
|
+
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
error.message="Error syncing jobs: "+error.message;
|
|
446
|
+
throw error;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async function saveJobsToCMS(updatedJobs) {
|
|
452
|
+
const chunkSize = 1000;
|
|
546
453
|
let totalSaved = 0;
|
|
547
454
|
const totalChunks = Math.ceil(updatedJobs.length / chunkSize);
|
|
548
455
|
|
|
@@ -569,35 +476,18 @@ async function syncJobsFast() {
|
|
|
569
476
|
},
|
|
570
477
|
});
|
|
571
478
|
console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${updatedJobs.length}`);
|
|
572
|
-
|
|
573
|
-
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
async function insertJobsReferencesToCustomValuesCollection() {
|
|
482
|
+
console.log("inserting jobs references to custom values collection");
|
|
574
483
|
|
|
575
|
-
|
|
576
|
-
console.log("customValues: ",customValues)
|
|
577
|
-
console.log("customValues.items: ",customValues.items)
|
|
484
|
+
let customValues = await getAllCustomValues();
|
|
578
485
|
|
|
579
486
|
for (const value of customValues.items) {
|
|
580
487
|
await insertJobsReference(value._id, value.valueId);
|
|
581
488
|
}
|
|
582
489
|
console.log("inserted jobs references to custom values collection successfully");
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
console.log("saved jobs descriptions and location apply url to CMS successfully");//change comment
|
|
586
|
-
|
|
587
|
-
await aggregateJobs();
|
|
588
|
-
await referenceJobs();
|
|
589
|
-
|
|
590
|
-
console.log("syncing jobs fast finished successfully");
|
|
591
|
-
|
|
592
|
-
}
|
|
593
|
-
catch (error) {
|
|
594
|
-
error.message="Error syncing jobs: "+error.message;
|
|
595
|
-
throw error;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
490
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
491
|
async function clearCollections() {
|
|
602
492
|
console.log("clearing collections");
|
|
603
493
|
if(siteconfig===undefined) {
|
|
@@ -606,7 +496,6 @@ async function clearCollections() {
|
|
|
606
496
|
await Promise.all([
|
|
607
497
|
wixData.truncate(COLLECTIONS.CITIES),
|
|
608
498
|
wixData.truncate(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
|
|
609
|
-
wixData.truncate(COLLECTIONS.JOBS),
|
|
610
499
|
wixData.truncate(COLLECTIONS.BRANDS),
|
|
611
500
|
siteconfig.customFields==="true" ? wixData.truncate(COLLECTIONS.CUSTOM_VALUES) : null,
|
|
612
501
|
siteconfig.customFields==="true" ? wixData.truncate(COLLECTIONS.CUSTOM_FIELDS) : null,
|
|
@@ -657,8 +546,8 @@ module.exports = {
|
|
|
657
546
|
referenceJobs,
|
|
658
547
|
aggregateJobs,
|
|
659
548
|
createCollections,
|
|
660
|
-
saveJobsDataToCMS,
|
|
661
|
-
saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS,
|
|
549
|
+
saveJobsDataToCMS: retrieveJobsData,
|
|
550
|
+
saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS: retrieveJobsDescriptionsAndLocationApplyUrlReferences,
|
|
662
551
|
aggregateJobsByFieldToCMS,
|
|
663
552
|
referenceJobsToField,
|
|
664
553
|
fillSecretManagerMirror,
|