sr-npm 1.7.556 → 1.7.558

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 +9 -8
  2. package/package.json +1 -1
package/backend/data.js CHANGED
@@ -52,7 +52,7 @@ function validateSingleDesiredBrand(desiredBrand) {
52
52
  throw new Error("Desired brand must be a single brand");
53
53
  }
54
54
  }
55
- function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues,jobToCustomValues) {
55
+ function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues,jobToCustomValues,customValuesToJobs) {
56
56
  const customFieldsArray = Array.isArray(position?.customField) ? position.customField : [];
57
57
  for (const field of customFieldsArray) {
58
58
  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
@@ -69,6 +69,7 @@ function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,custom
69
69
  customFieldsValues[fieldId][valueId] = valueLabel;
70
70
 
71
71
  jobToCustomValues[position.id] ? jobToCustomValues[position.id].push(valueId) : jobToCustomValues[position.id]=[valueId]
72
+ customValuesToJobs[valueId] ? customValuesToJobs[valueId].push(position.id) : customValuesToJobs[valueId]=[position.id]
72
73
  }
73
74
 
74
75
  }
@@ -78,6 +79,7 @@ async function saveJobsDataToCMS() {
78
79
  const customFieldsLabels = {}
79
80
  const customFieldsValues = {}
80
81
  const jobToCustomValues = {}
82
+ const customValuesToJobs = {}
81
83
 
82
84
  // bulk insert to jobs collection without descriptions first
83
85
  const jobsData = sourcePositions.map(position => {
@@ -105,7 +107,7 @@ async function saveJobsDataToCMS() {
105
107
  jobDescription: null, // Will be filled later
106
108
  };
107
109
 
108
- getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues,jobToCustomValues);
110
+ getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues,jobToCustomValues,customValuesToJobs);
109
111
  return basicJob;
110
112
  });
111
113
 
@@ -151,7 +153,7 @@ async function saveJobsDataToCMS() {
151
153
 
152
154
  await insertValuesReference(jobToCustomValues);
153
155
  console.log("inserted values reference successfully");
154
- await insertJobsReference(jobToCustomValues);
156
+ await insertJobsReference(customValuesToJobs);
155
157
  console.log("inserted jobs reference successfully");
156
158
 
157
159
  console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
@@ -165,12 +167,11 @@ async function insertValuesReference(jobToCustomValues) {
165
167
  }
166
168
  console.log("inserted values reference successfully");
167
169
  }
168
- async function insertJobsReference(jobToCustomValues) {
170
+ async function insertJobsReference(customValuesToJobs) {
169
171
  console.log("inserting jobs reference");
170
- for (const jobId of Object.keys(jobToCustomValues)) {
171
- for (const valueId of jobToCustomValues[jobId]) {
172
- await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,valueId, jobId);
173
- }
172
+ for (const valueId of Object.keys(customValuesToJobs)) {
173
+ const items = customValuesToJobs[valueId];
174
+ await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,valueId, items);
174
175
  }
175
176
  console.log("inserted jobs reference successfully");
176
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.556",
3
+ "version": "1.7.558",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {