sr-npm 1.7.541 → 1.7.543
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/collectionConsts.js +2 -2
- package/backend/data.js +17 -2
- package/package.json +1 -1
|
@@ -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: {
|
|
76
|
+
{key:'customValues', type: 'MULTI_REFERENCE', typeMetadata: { multiReference: { referencedCollectionId: COLLECTIONS.CUSTOM_VALUES,referencingFieldKey:'customValues',referencingDisplayName:'customValues' } } },
|
|
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: {
|
|
100
|
+
{key:'jobs', type: 'MULTI_REFERENCE', typeMetadata: { multiReference: { referencedCollectionId: COLLECTIONS.JOBS,referencingFieldKey:'jobs',referencingDisplayName:'jobs' } } },
|
|
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,9 +104,11 @@ async function saveJobsDataToCMS() {
|
|
|
100
104
|
brand: getBrand(position.customField),
|
|
101
105
|
jobDescription: null, // Will be filled later
|
|
102
106
|
};
|
|
103
|
-
|
|
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);
|
|
108
114
|
populateCustomFieldsCollection(customFieldsLabels);
|
|
@@ -141,10 +147,19 @@ async function saveJobsDataToCMS() {
|
|
|
141
147
|
}
|
|
142
148
|
},
|
|
143
149
|
});
|
|
150
|
+
|
|
151
|
+
await insertValuesReference(jobToCustomValues);
|
|
144
152
|
|
|
145
153
|
console.log(`✓ All chunks processed. Total jobs saved: ${totalSaved}/${jobsData.length}`);
|
|
146
154
|
}
|
|
147
155
|
|
|
156
|
+
async function insertValuesReference(jobToCustomValues) {
|
|
157
|
+
for (const jobId of Object.keys(jobToCustomValues)) {
|
|
158
|
+
const items = jobToCustomValues[jobId];
|
|
159
|
+
await wixData.insertReference(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.CUSTOM_VALUES,jobId, items);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
148
163
|
function populateCustomFieldsCollection(customFields) {
|
|
149
164
|
for(const ID of Object.keys(customFields)){
|
|
150
165
|
wixData.save(COLLECTIONS.CUSTOM_FIELDS, {
|