sr-npm 1.7.536 → 1.7.538

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.
@@ -36,6 +36,7 @@ const AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS = {
36
36
  const CUSTOM_VALUES_COLLECTION_FIELDS = {
37
37
  TITLE: 'title',
38
38
  CUSTOM_FIELD: 'customField',
39
+ JOBS: 'jobs',
39
40
  }
40
41
  const CUSTOM_FIELDS_COLLECTION_FIELDS = {
41
42
  TITLE: 'title',
@@ -97,6 +98,7 @@ const COLLECTIONS_FIELDS = {
97
98
  CUSTOM_VALUES: [
98
99
  {key:'title', type: 'TEXT'},
99
100
  {key:'customField', type: 'REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.CUSTOM_FIELDS } } },
101
+ {key:'jobs', type: 'MULTI-REFERENCE', typeMetadata: { reference: { referencedCollectionId: COLLECTIONS.JOBS } } },
100
102
  ],
101
103
  CUSTOM_FIELDS: [
102
104
  {key:'title', type: 'TEXT'},
package/backend/data.js CHANGED
@@ -52,21 +52,29 @@ function validateSingleDesiredBrand(desiredBrand) {
52
52
  throw new Error("Desired brand must be a single brand");
53
53
  }
54
54
  }
55
- function getCustomFieldsAndValuesFromPosition(position,customFields) {
55
+ function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues) {
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
59
59
  const label = field.fieldLabel==="Brands" ? "brand" : field.fieldLabel
60
- const key = normalizeString(label);
61
- const value = field.valueLabel
62
- customFields[key] ? customFields[key].add(value) : customFields[key]=new Set([value])
60
+ const fieldId=field.fieldId
61
+ const fieldLabel = normalizeString(label);
62
+ const valueId=field.valueId
63
+ const valueLabel = field.valueLabel
64
+ customFieldsLabels[fieldId] = fieldLabel
65
+ // Build nested dictionary: fieldId -> { valueId: valueLabel }
66
+ if (!customFieldsValues[fieldId]) {
67
+ customFieldsValues[fieldId] = {};
68
+ }
69
+ customFieldsValues[fieldId][valueId] = valueLabel;
63
70
  }
64
71
 
65
72
  }
66
73
  async function saveJobsDataToCMS() {
67
74
  const positions = await fetchPositionsFromSRAPI();
68
75
  const sourcePositions = await filterBasedOnBrand(positions);
69
- const customFields = {}
76
+ const customFieldsLabels = {}
77
+ const customFieldsValues = {}
70
78
  // bulk insert to jobs collection without descriptions first
71
79
  const jobsData = sourcePositions.map(position => {
72
80
  const basicJob = {
@@ -92,12 +100,13 @@ async function saveJobsDataToCMS() {
92
100
  brand: getBrand(position.customField),
93
101
  jobDescription: null, // Will be filled later
94
102
  };
95
- getCustomFieldsAndValuesFromPosition(position,customFields);
103
+ getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues);
96
104
  return basicJob;
97
105
  });
98
- console.log("customFields: ", customFields);
99
- populateCustomFieldsCollection(customFields);
100
- populateCustomValuesCollection(customFields);
106
+ console.log("customFieldsLabels: ", customFieldsLabels);
107
+ console.log("customFieldsValues: ", customFieldsValues);
108
+ populateCustomFieldsCollection(customFieldsLabels);
109
+ populateCustomValuesCollection(customFieldsValues);
101
110
  // Sort jobs by title (ascending, case-insensitive, numeric-aware)
102
111
  jobsData.sort((a, b) => {
103
112
  const titleA = a.title || '';
@@ -137,18 +146,23 @@ async function saveJobsDataToCMS() {
137
146
  }
138
147
 
139
148
  function populateCustomFieldsCollection(customFields) {
140
- for(const key of Object.keys(customFields)){
149
+ for(const ID of Object.keys(customFields)){
141
150
  wixData.save(COLLECTIONS.CUSTOM_FIELDS, {
142
- title: key,
151
+ title: customFields[ID],
152
+ _id: ID,
143
153
  });
144
154
  }
145
155
  }
146
- function populateCustomValuesCollection(customFields) {
147
- for(const key of Object.keys(customFields)){
148
- wixData.save(COLLECTIONS.CUSTOM_VALUES, {
149
- title: key,
150
- customField: customFields[key],
151
- });
156
+ function populateCustomValuesCollection(customFieldsValues) {
157
+ for (const fieldId of Object.keys(customFieldsValues)) {
158
+ const valuesMap = customFieldsValues[fieldId] || {};
159
+ for (const valueId of Object.keys(valuesMap)) {
160
+ wixData.save(COLLECTIONS.CUSTOM_VALUES, {
161
+ _id: valueId,
162
+ title: valuesMap[valueId],
163
+ customField: fieldId, // reference to CustomFields collection (displays the label)
164
+ });
165
+ }
152
166
  }
153
167
  }
154
168
  async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
@@ -354,13 +368,13 @@ function fetchJobLocation(jobDetails) {
354
368
  async function createCollections() {
355
369
  console.log("Creating collections");
356
370
  await Promise.all(
357
- [createCollectionIfMissing(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.JOBS,{ insert: 'ADMIN', update: 'ADMIN', remove: 'ADMIN', read: 'ANYONE' }),
371
+ [createCollectionIfMissing(COLLECTIONS.JOBS, COLLECTIONS_FIELDS.JOBS,{ insert: 'ADMIN', update: 'ADMIN', remove: 'ADMIN', read: 'ANYONE' }),
358
372
  createCollectionIfMissing(COLLECTIONS.CITIES, COLLECTIONS_FIELDS.CITIES),
359
373
  createCollectionIfMissing(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, COLLECTIONS_FIELDS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
360
374
  createCollectionIfMissing(COLLECTIONS.SECRET_MANAGER_MIRROR, COLLECTIONS_FIELDS.SECRET_MANAGER_MIRROR),
361
375
  createCollectionIfMissing(COLLECTIONS.BRANDS, COLLECTIONS_FIELDS.BRANDS),
362
- createCollectionIfMissing(COLLECTIONS.CUSTOM_VALUES, CUSTOM_VALUES_COLLECTION_FIELDS.CUSTOM_VALUES),
363
- createCollectionIfMissing(COLLECTIONS.CUSTOM_FIELDS, CUSTOM_FIELDS_COLLECTION_FIELDS.CUSTOM_FIELDS)
376
+ createCollectionIfMissing(COLLECTIONS.CUSTOM_VALUES, COLLECTIONS_FIELDS.CUSTOM_VALUES),
377
+ createCollectionIfMissing(COLLECTIONS.CUSTOM_FIELDS, COLLECTIONS_FIELDS.CUSTOM_FIELDS)
364
378
  ]);
365
379
  console.log("finished creating Collections");
366
380
  }
@@ -387,7 +401,7 @@ async function referenceJobs() {
387
401
  async function syncJobsFast() {
388
402
  console.log("Syncing jobs fast");
389
403
  await createCollections();
390
- // await clearCollections();
404
+ await clearCollections();
391
405
  // await fillSecretManagerMirror();
392
406
  console.log("saving jobs data to CMS");
393
407
  await saveJobsDataToCMS();
@@ -406,7 +420,9 @@ async function clearCollections() {
406
420
  wixData.truncate(COLLECTIONS.CITIES),
407
421
  wixData.truncate(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
408
422
  wixData.truncate(COLLECTIONS.JOBS),
409
- wixData.truncate(COLLECTIONS.BRANDS)
423
+ wixData.truncate(COLLECTIONS.BRANDS),
424
+ wixData.truncate(COLLECTIONS.CUSTOM_VALUES),
425
+ wixData.truncate(COLLECTIONS.CUSTOM_FIELDS),
410
426
  ]);
411
427
  console.log("cleared collections successfully");
412
428
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.536",
3
+ "version": "1.7.538",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {