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