sr-npm 1.7.638 → 1.7.640

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.
@@ -54,6 +54,7 @@ const CITIES_COLLECTION_FIELDS = {
54
54
  LOCATION_ADDRESS: 'locationAddress',
55
55
  COUNT: 'count',
56
56
  COUNTRY: 'country',
57
+ JOB_IDS: 'jobIds',
57
58
  }
58
59
  const COLLECTIONS_FIELDS = {
59
60
  AMOUNT_OF_JOBS_PER_DEPARTMENT: [
@@ -67,6 +68,7 @@ const COLLECTIONS_FIELDS = {
67
68
  {key:'locationAddress', type: 'ADDRESS'},
68
69
  {key:'count', type: 'NUMBER'},
69
70
  {key:'country', type: 'TEXT'},
71
+ {key:'jobIds', type: 'ARRAY'},
70
72
  ],
71
73
  JOBS: [
72
74
  {key:'location', type: 'OBJECT'},
package/backend/data.js CHANGED
@@ -7,8 +7,9 @@ const { getAllPositions } = require('./queries');
7
7
  const { retrieveSecretVal, getTokenFromCMS } = require('./secretsData');
8
8
 
9
9
 
10
- let jobToCustomValues = {}
10
+ //let jobToCustomValues = {}
11
11
  let customValuesToJobs = {}
12
+ let locationToJobs = {}
12
13
  let siteconfig;
13
14
  const EXCLUDED_CUSTOM_FIELDS = new Set(["Department"]);
14
15
 
@@ -62,12 +63,17 @@ function validateSingleDesiredBrand(desiredBrand) {
62
63
  throw new Error("Desired brand must be a single brand");
63
64
  }
64
65
  }
66
+ function getLocation(position,basicJob) {
67
+
68
+ locationToJobs[basicJob.cityText] ? locationToJobs[basicJob.cityText].push(position.id) : locationToJobs[basicJob.cityText]=[position.id]
69
+
70
+ }
65
71
  function getEmploymentType(position,customFieldsValues) {
66
72
  if (!customFieldsValues["employmentType"]) {
67
73
  customFieldsValues["employmentType"] = {};
68
74
  }
69
75
  customFieldsValues["employmentType"][position.typeOfEmployment.id] = position.typeOfEmployment.label;
70
- jobToCustomValues[position.id] ? jobToCustomValues[position.id].push(position.typeOfEmployment.id) : jobToCustomValues[position.id]=[position.typeOfEmployment.id]
76
+ //jobToCustomValues[position.id] ? jobToCustomValues[position.id].push(position.typeOfEmployment.id) : jobToCustomValues[position.id]=[position.typeOfEmployment.id]
71
77
  customValuesToJobs[position.typeOfEmployment.id] ? customValuesToJobs[position.typeOfEmployment.id].push(position.id) : customValuesToJobs[position.typeOfEmployment.id]=[position.id]
72
78
  }
73
79
 
@@ -86,7 +92,7 @@ function getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,custom
86
92
  }
87
93
  customFieldsValues[fieldId][valueId] = valueLabel;
88
94
 
89
- jobToCustomValues[position.id] ? jobToCustomValues[position.id].push(valueId) : jobToCustomValues[position.id]=[valueId]
95
+ //jobToCustomValues[position.id] ? jobToCustomValues[position.id].push(valueId) : jobToCustomValues[position.id]=[valueId]
90
96
  customValuesToJobs[valueId] ? customValuesToJobs[valueId].push(position.id) : customValuesToJobs[valueId]=[position.id]
91
97
  }
92
98
  }
@@ -125,6 +131,7 @@ async function saveJobsDataToCMS() {
125
131
 
126
132
  getCustomFieldsAndValuesFromPosition(position,customFieldsLabels,customFieldsValues);
127
133
  getEmploymentType(position,customFieldsValues);
134
+ getLocation(position,basicJob);
128
135
  return basicJob;
129
136
  });
130
137
  if(siteconfig===undefined) {
@@ -309,7 +316,7 @@ async function aggregateJobsByFieldToCMS({ field, collection }) {
309
316
  console.log(`counting jobs per ${field}.`);
310
317
  let results = await getAllPositions();
311
318
  const { jobsPerField, cityLocations,citylocationAddress } = iterateOverAllJobs(results, field);
312
- const toSave = prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddress);
319
+ const toSave = prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddress,locationToJobs);
313
320
  if (toSave.length === 0) {
314
321
  console.log('No jobs found.');
315
322
  return { success: true, message: 'No jobs to save.' };
package/backend/utils.js CHANGED
@@ -30,7 +30,7 @@ function fillCityLocationAndLocationAddress(jobs, cityLocations,citylocationAddr
30
30
  }
31
31
  }
32
32
 
33
- function prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddress) {
33
+ function prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddress,customValuesToJobs=null) {
34
34
  if (field === 'cityText') {
35
35
  return Object.entries(jobsPerField).map(([value, amount]) => {
36
36
  const loc = cityLocations[value] || {};
@@ -43,6 +43,7 @@ function prepareToSaveArray(jobsPerField, cityLocations, field,citylocationAddre
43
43
  locationAddress: locAddress,
44
44
  country: loc.country,
45
45
  city: loc.city,
46
+ jobIds: customValuesToJobs[value],
46
47
  };
47
48
  });
48
49
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.638",
3
+ "version": "1.7.640",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,8 +1,7 @@
1
1
  const { COLLECTIONS,CUSTOM_VALUES_COLLECTION_FIELDS,JOBS_COLLECTION_FIELDS } = require('../backend/collectionConsts');
2
2
  const { items: wixData } = require('@wix/data');
3
3
  const {CAREERS_MULTI_BOXES_PAGE_CONSTS} = require('../backend/careersMultiBoxesPageIds');
4
- const { auth } = require('@wix/essentials');
5
- const getAllRecordsElevated = auth.elevate(wixData.query);
4
+
6
5
  let valuesByFieldIdGlobal = null;
7
6
  let dontUpdateThisCheckBox;
8
7
  const selectedByField = new Map(); // fieldId -> array of selected value IDs
@@ -19,6 +18,7 @@ async function careersMultiBoxesPageOnReady(_$w) {
19
18
  }
20
19
  if(Object.keys(valueToJobs).length === 0){
21
20
  allvaluesobjects=await getAllRecords(COLLECTIONS.CUSTOM_VALUES);
21
+
22
22
  for (const value of allvaluesobjects) {
23
23
  valueToJobs[value._id]= value.jobIds;
24
24
  }
@@ -82,7 +82,8 @@ async function loadJobs(_$w) {
82
82
  async function loadFilters(_$w) {
83
83
  try {
84
84
  // 1) Load all categories (fields)
85
- const fields = await getAllRecords(COLLECTIONS.CUSTOM_FIELDS);
85
+ let fields = await getAllRecords(COLLECTIONS.CUSTOM_FIELDS);
86
+ fields.push({_id:"Location",title:"Location"});
86
87
  console.log("fields: ",fields)
87
88
  _$w(CAREERS_MULTI_BOXES_PAGE_CONSTS.FILTER_REPEATER).data = fields;
88
89
  const cities=await getAllRecords(COLLECTIONS.CITIES);
@@ -156,15 +157,14 @@ async function loadJobs(_$w) {
156
157
  console.error('Failed to load filters:', err);
157
158
  }
158
159
  }
159
-
160
+
160
161
 
161
162
  async function getAllRecords(collectionId) {
162
- //let q = wixData.query(collectionId);
163
- let q=getAllRecordsElevated(collectionId)
163
+ let q = wixData.query(collectionId);
164
164
 
165
165
 
166
166
  const items = [];
167
- let res = await q.limit(1000).find()
167
+ let res = await q.limit(1000).find();
168
168
  items.push(...res.items);
169
169
 
170
170
  while (res.hasNext()) {