sr-npm 1.7.555 → 1.7.557
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 +15 -15
- 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,25 +153,28 @@ async function saveJobsDataToCMS() {
|
|
|
151
153
|
|
|
152
154
|
await insertValuesReference(jobToCustomValues);
|
|
153
155
|
console.log("inserted values reference successfully");
|
|
154
|
-
await insertJobsReference(
|
|
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}`);
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
async function insertValuesReference(jobToCustomValues) {
|
|
163
|
+
console.log("inserting values reference");
|
|
161
164
|
for (const jobId of Object.keys(jobToCustomValues)) {
|
|
162
165
|
const items = jobToCustomValues[jobId];
|
|
163
166
|
await wixData.insertReference(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,jobId, items);
|
|
164
167
|
}
|
|
168
|
+
console.log("inserted values reference successfully");
|
|
165
169
|
}
|
|
166
|
-
async function insertJobsReference(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
async function insertJobsReference(customValuesToJobs) {
|
|
171
|
+
console.log("inserting jobs reference");
|
|
172
|
+
console.log("jobToCustomValues: ", jobToCustomValues);
|
|
173
|
+
for (const valueId of Object.keys(customValuesToJobs)) {
|
|
174
|
+
const items = customValuesToJobs[valueId];
|
|
175
|
+
await wixData.insertReference(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.MULTI_REF_JOBS_CUSTOM_VALUES,valueId, items);
|
|
171
176
|
}
|
|
172
|
-
|
|
177
|
+
console.log("inserted jobs reference successfully");
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
async function populateCustomFieldsCollection(customFields) {
|
|
@@ -181,21 +186,16 @@ async function populateCustomFieldsCollection(customFields) {
|
|
|
181
186
|
}
|
|
182
187
|
}
|
|
183
188
|
async function populateCustomValuesCollection(customFieldsValues) {
|
|
184
|
-
console.log("populating custom values collection");
|
|
185
|
-
console.log("customFieldsValues: ", customFieldsValues);
|
|
186
189
|
for (const fieldId of Object.keys(customFieldsValues)) {
|
|
187
|
-
console.log("populating custom values for field: ", fieldId);
|
|
188
190
|
const valuesMap = customFieldsValues[fieldId] || {};
|
|
189
191
|
for (const valueId of Object.keys(valuesMap)) {
|
|
190
|
-
console.log("populating custom values for value: ", valueId);
|
|
191
192
|
await wixData.save(COLLECTIONS.CUSTOM_VALUES, {
|
|
192
193
|
_id: valueId,
|
|
193
194
|
title: valuesMap[valueId],
|
|
194
|
-
|
|
195
|
+
customField: fieldId, // reference to CustomFields collection (displays the label)
|
|
195
196
|
});
|
|
196
197
|
}
|
|
197
198
|
}
|
|
198
|
-
console.log("populated custom values collection successfully");
|
|
199
199
|
}
|
|
200
200
|
async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
|
|
201
201
|
console.log('🚀 Starting job descriptions update process for ALL jobs');
|