sr-npm 1.7.561 → 1.7.563

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 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,jobToCustomValues,customValuesToJobs) {
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
- getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues,jobToCustomValues,customValuesToJobs);
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,customValuesToJobs);
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(jobToCustomValues) {
165
- console.log("inserting values reference");
166
- for (const jobId of Object.keys(jobToCustomValues)) {
167
- const items = jobToCustomValues[jobId];
168
- await wixData.insertReference(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,jobId, items);
169
- }
170
- console.log("inserted values reference successfully");
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(customValuesToJobs) {
173
- console.log("inserting jobs reference");
174
- for (const valueId of Object.keys(customValuesToJobs)) {
175
- const items = customValuesToJobs[valueId];
176
- await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,valueId, items);
177
- }
178
- console.log("inserted jobs reference successfully");
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,customValuesToJobs) {
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,28 @@ 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 saveJobsDescriptionsAndLocationApplyUrlToCMS() {
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
+ console.log("customValues: ", customValues);
215
+ console.log("jobToCustomValues: ", jobToCustomValues);
216
+ console.log("customValuesToJobs: ", customValuesToJobs);
217
+
218
+ console.log("inserting jobs references");
219
+ for (const value of customValues.items) {
220
+ await insertJobsReference(value._id);
221
+ }
222
+ console.log("inserted jobs references successfully");
223
+
224
+
211
225
  let totalUpdated = 0;
212
226
  let totalFailed = 0;
213
227
  let totalProcessed = 0;
@@ -236,7 +250,7 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
236
250
  const jobLocation = fetchJobLocation(jobDetails);
237
251
  const {applyLink , referFriendLink} = fetchApplyAndReferFriendLink(jobDetails);
238
252
 
239
-
253
+
240
254
  const updatedJob = {
241
255
  ...job,
242
256
  locationAddress: jobLocation,
@@ -245,6 +259,7 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
245
259
  referFriendLink: referFriendLink,
246
260
  };
247
261
  await wixData.update(COLLECTIONS.JOBS, updatedJob);
262
+ await insertValuesReference(job._id);
248
263
  return { success: true, jobId: job._id, title: job.title };
249
264
  } catch (error) {
250
265
  console.error(` ❌ Failed to update ${job.title} (${job._id}):`, error);
@@ -316,7 +331,10 @@ async function aggregateJobsByFieldToCMS({ field, collection }) {
316
331
  return { success: false, error: err.message };
317
332
  }
318
333
  }
319
-
334
+ async function getAllCustomValues() {
335
+ let customValuesQuery = await wixData.query(COLLECTIONS.CUSTOM_VALUES).limit(1000).find();
336
+ return customValuesQuery;
337
+ }
320
338
  async function getJobsWithNoDescriptions() {
321
339
  let jobswithoutdescriptionsQuery = await wixData
322
340
  .query(COLLECTIONS.JOBS)
@@ -444,12 +462,29 @@ async function syncJobsFast() {
444
462
  await saveJobsDataToCMS();
445
463
  console.log("saved jobs data to CMS successfully");
446
464
  console.log("saving jobs descriptions and location apply url to CMS");
447
- await saveJobsDescriptionsAndLocationApplyUrlToCMS();
465
+ await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
448
466
  console.log("saved jobs descriptions and location apply url to CMS successfully");
449
467
  await aggregateJobs();
450
468
  await referenceJobs();
451
469
  console.log("syncing jobs fast finished successfully");
452
470
  }
471
+ async function syncJobsFastSplitted() {
472
+ console.log("Syncing jobs fast");
473
+ await createCollections();
474
+ await clearCollections();
475
+ await fillSecretManagerMirror();
476
+ console.log("saving jobs data to CMS");
477
+ await saveJobsDataToCMS();
478
+ console.log("saved jobs data to CMS successfully");
479
+ await aggregateJobs();
480
+ await referenceJobs();
481
+ console.log("syncing jobs fast finished successfully");
482
+ }
483
+ async function syncJobsDescriptionsAndLocationApplyUrlFastSplitted() {
484
+ console.log("Syncing jobs descriptions and location apply url and values references");
485
+ await saveJobsDescriptionsAndLocationApplyUrlReferencesToCMS();
486
+ console.log("saved jobs descriptions and location apply url and values references successfully");
487
+ }
453
488
 
454
489
  async function clearCollections() {
455
490
  console.log("clearing collections");
@@ -508,7 +543,8 @@ module.exports = {
508
543
  aggregateJobs,
509
544
  createCollections,
510
545
  saveJobsDataToCMS,
511
- saveJobsDescriptionsAndLocationApplyUrlToCMS,
546
+ syncJobsFastSplitted,
547
+ syncJobsDescriptionsAndLocationApplyUrlFastSplitted,
512
548
  aggregateJobsByFieldToCMS,
513
549
  referenceJobsToField,
514
550
  fillSecretManagerMirror,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.561",
3
+ "version": "1.7.563",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {