sr-npm 1.7.542 → 1.7.544

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.
@@ -25,7 +25,7 @@ const JOBS_COLLECTION_FIELDS = {
25
25
  REFER_FRIEND_LINK: 'referFriendLink',
26
26
  BRAND: 'brand',
27
27
  BRAND_REF: 'brandRef',
28
- CUSTOM_VALUES: 'customValues',
28
+ MULTI_REF_JOBS_CUSTOM_VALUES: 'multiRefJobsCustomValues',
29
29
  }
30
30
  const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
31
31
  TITLE: 'title',
@@ -35,7 +35,7 @@ const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
35
35
  const CUSTOM_VALUES_COLLECTION_FIELDS = {
36
36
  TITLE: 'title',
37
37
  CUSTOM_FIELD: 'customField',
38
- JOBS: 'jobs',
38
+ MULTI_REF_JOBS_CUSTOM_VALUES: 'multiRefJobsCustomValues',
39
39
  }
40
40
  const CUSTOM_FIELDS_COLLECTION_FIELDS = {
41
41
  TITLE: 'title',
@@ -73,7 +73,7 @@ const COLLECTIONS_FIELDS = {
73
73
  {key:'language', type: 'TEXT'},
74
74
  {key:'remote', type: 'BOOLEAN'},
75
75
  {key:'jobDescription', type: 'OBJECT'},
76
- {key:'customValues', type: 'MULTI_REFERENCE', typeMetadata: { multiReference: { referencedCollectionId: COLLECTIONS.CUSTOM_VALUES,referencingFieldKey:'customValues',referencingDisplayName:'customValues' } } },
76
+ {key:'multiRefJobsCustomValues', type: 'MULTI_REFERENCE', typeMetadata: { multiReference: { referencedCollectionId: COLLECTIONS.CUSTOM_VALUES,referencingFieldKey:CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,referencingDisplayName:CUSTOM_VALUES_COLLECTION_FIELDS.TITLE } } },
77
77
  {key:'cityText', type: 'TEXT'},
78
78
  {key:'applyLink', type: 'URL'},
79
79
  {key:'referFriendLink', type: 'URL'},
@@ -97,7 +97,7 @@ const COLLECTIONS_FIELDS = {
97
97
  CUSTOM_VALUES: [
98
98
  {key:'title', type: 'TEXT'},
99
99
  {key:'customField', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CUSTOM_FIELDS } } },
100
- {key:'jobs', type: 'MULTI_REFERENCE', typeMetadata: { multiReference: { referencedCollectionId: COLLECTIONS.JOBS,referencingFieldKey:'jobs',referencingDisplayName:'jobs' } } },
100
+ {key:'multiRefJobsCustomValues', type: 'MULTI_REFERENCE', typeMetadata: { multiReference: { referencedCollectionId: COLLECTIONS.JOBS,referencingFieldKey:JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,referencingDisplayName:JOBS_COLLECTION_FIELDS.TITLE } } },
101
101
  ],
102
102
  CUSTOM_FIELDS: [
103
103
  {key:'title', type: 'TEXT'},
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) {
55
+ function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues,jobToCustomValues) {
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") continue; //country and department are not custom fields, they are already in the job object
@@ -67,6 +67,8 @@ function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,custom
67
67
  customFieldsValues[fieldId] = {};
68
68
  }
69
69
  customFieldsValues[fieldId][valueId] = valueLabel;
70
+
71
+ jobToCustomValues[position.id] ? jobToCustomValues[position.id].push(valueId) : jobToCustomValues[position.id]=[valueId]
70
72
  }
71
73
 
72
74
  }
@@ -75,6 +77,8 @@ async function saveJobsDataToCMS() {
75
77
  const sourcePositions = await filterBasedOnBrand(positions);
76
78
  const customFieldsLabels = {}
77
79
  const customFieldsValues = {}
80
+ const jobToCustomValues = {}
81
+
78
82
  // bulk insert to jobs collection without descriptions first
79
83
  const jobsData = sourcePositions.map(position => {
80
84
  const basicJob = {
@@ -100,11 +104,14 @@ async function saveJobsDataToCMS() {
100
104
  brand: getBrand(position.customField),
101
105
  jobDescription: null, // Will be filled later
102
106
  };
103
- getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues);
107
+
108
+ getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues,jobToCustomValues);
104
109
  return basicJob;
105
110
  });
111
+
106
112
  console.log("customFieldsLabels: ", customFieldsLabels);
107
113
  console.log("customFieldsValues: ", customFieldsValues);
114
+ console.log("jobToCustomValues: ", jobToCustomValues);
108
115
  populateCustomFieldsCollection(customFieldsLabels);
109
116
  populateCustomValuesCollection(customFieldsValues);
110
117
  // Sort jobs by title (ascending, case-insensitive, numeric-aware)
@@ -142,9 +149,27 @@ async function saveJobsDataToCMS() {
142
149
  },
143
150
  });
144
151
 
152
+ await insertValuesReference(jobToCustomValues);
153
+ await insertJOBSsReference(jobToCustomValues);
154
+
155
+
145
156
  console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
146
157
  }
147
158
 
159
+ async function insertValuesReference(jobToCustomValues) {
160
+ for (const jobId of Object.keys(jobToCustomValues)) {
161
+ const items = jobToCustomValues[jobId];
162
+ await wixData.insertReference(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,jobId, items);
163
+ }
164
+ }
165
+ async function insertJOBSsReference(jobToCustomValues) {
166
+ for (const jobId of Object.keys(jobToCustomValues)) {
167
+ for (const valueId of jobToCustomValues[jobId]) {
168
+ await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,valueId, jobId);
169
+ }
170
+ }
171
+ }
172
+
148
173
  function populateCustomFieldsCollection(customFields) {
149
174
  for(const ID of Object.keys(customFields)){
150
175
  wixData.save(COLLECTIONS.CUSTOM_FIELDS, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.542",
3
+ "version": "1.7.544",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {