sr-npm 1.7.1320 → 1.7.1322

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.
Files changed (2) hide show
  1. package/backend/data.js +42 -161
  2. 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 saveJobsDataToCMS() {
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
- console.log("populating custom fields collection");
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 saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS(jobsWithNoDescriptions) {
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
- async function getJobsWithNoDescriptions() {
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,47 @@ async function syncJobsFast() {
530
410
  try{
531
411
  console.log("Syncing jobs fast");
532
412
  await createCollections();
533
- await clearCollections();
413
+ await clearCollections();
534
414
  await fillSecretManagerMirror();
535
415
 
536
- console.log("saving jobs data to CMS");//change comment
537
- const jobsData = await saveJobsDataToCMS(); //change name
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("saved jobs data to CMS successfully");//change comment
419
+ console.log("retrieved jobs data from SR API successfully");
540
420
 
541
- console.log("saving jobs descriptions and location apply url to CMS");//change comment
542
- const status=await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS(jobsData);
421
+ console.log("retrieving jobs descriptions and location apply url from SR API");
543
422
 
423
+ const status=await retrieveJobsDescriptionsAndLocationApplyUrlReferences(jobsData);
424
+ throw new Error("test");
544
425
  console.log("status inside syncJobsFast: ",status);
545
426
  if(status.success){
546
427
  await wixData.truncate(COLLECTIONS.JOBS)
547
- //await clearCollections();
548
428
  const updatedJobs=status.updatedJobs;
549
- const chunkSize = 1000;
429
+ console.log("updatedJobs inside syncJobsFast: ",updatedJobs);
430
+ await saveJobsToCMS(updatedJobs);
431
+ console.log("saved jobs to CMS successfully");
432
+
433
+ if (siteconfig.customFields==="true") {
434
+ await insertJobsReferencesToCustomValuesCollection();
435
+ }
436
+ }
437
+ console.log("saved jobs data, descriptions and location apply url to CMS successfully");
438
+
439
+ await aggregateJobs();
440
+ await referenceJobs();
441
+
442
+ console.log("syncing jobs fast finished successfully");
443
+
444
+ }
445
+ catch (error) {
446
+ error.message="Error syncing jobs: "+error.message;
447
+ throw error;
448
+ }
449
+
450
+ }
451
+
452
+ async function saveJobsToCMS(updatedJobs) {
453
+ const chunkSize = 1000;
550
454
  let totalSaved = 0;
551
455
  const totalChunks = Math.ceil(updatedJobs.length / chunkSize);
552
456
 
@@ -573,40 +477,18 @@ async function syncJobsFast() {
573
477
  },
574
478
  });
575
479
  console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${updatedJobs.length}`);
576
- if (siteconfig.customFields==="true") {
577
- console.log("inserting jobs references to custom values collection");
480
+ }
578
481
 
579
- //put this inside function
580
- //------------------------------------------------------------------------------------------------
581
- let customValues = await getAllCustomValues();
482
+ async function insertJobsReferencesToCustomValuesCollection() {
483
+ console.log("inserting jobs references to custom values collection");
582
484
 
583
- console.log("inserting jobs references to custom values collection");
584
- console.log("customValues: ",customValues)
585
- console.log("customValues.items: ",customValues.items)
485
+ let customValues = await getAllCustomValues();
586
486
 
587
487
  for (const value of customValues.items) {
588
488
  await insertJobsReference(value._id, value.valueId);
589
489
  }
590
490
  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
491
  }
608
-
609
-
610
492
  async function clearCollections() {
611
493
  console.log("clearing collections");
612
494
  if(siteconfig===undefined) {
@@ -615,7 +497,6 @@ async function clearCollections() {
615
497
  await Promise.all([
616
498
  wixData.truncate(COLLECTIONS.CITIES),
617
499
  wixData.truncate(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
618
- //wixData.truncate(COLLECTIONS.JOBS),
619
500
  wixData.truncate(COLLECTIONS.BRANDS),
620
501
  siteconfig.customFields==="true" ? wixData.truncate(COLLECTIONS.CUSTOM_VALUES) : null,
621
502
  siteconfig.customFields==="true" ? wixData.truncate(COLLECTIONS.CUSTOM_FIELDS) : null,
@@ -666,8 +547,8 @@ module.exports = {
666
547
  referenceJobs,
667
548
  aggregateJobs,
668
549
  createCollections,
669
- saveJobsDataToCMS,
670
- saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS,
550
+ saveJobsDataToCMS: retrieveJobsData,
551
+ saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS: retrieveJobsDescriptionsAndLocationApplyUrlReferences,
671
552
  aggregateJobsByFieldToCMS,
672
553
  referenceJobsToField,
673
554
  fillSecretManagerMirror,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.1320",
3
+ "version": "1.7.1322",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {