sr-npm 1.7.494 → 1.7.496

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.
Files changed (2) hide show
  1. package/backend/data.js +26 -8
  2. package/package.json +1 -1
package/backend/data.js CHANGED
@@ -26,16 +26,34 @@ function validatePosition(position) {
26
26
 
27
27
  }
28
28
 
29
+ async function filterBasedOnBrand(positions) {
30
+ try{
31
+ const desiredBrand = await getTokenFromCMS(TOKEN_NAME.DESIRED_BRAND);
32
+ validateSingleDesiredBrand(desiredBrand);
33
+ console.log("filtering positions based on brand: ", desiredBrand);
34
+ return positions.content.filter(position => {
35
+ const brand = getBrand(position.customField);
36
+ if (!brand) return false;
37
+ return brand === desiredBrand;
38
+ });
39
+ } catch (error) {
40
+ if(error.message === "Desired brand must be a single brand"){
41
+ throw error;
42
+ }
43
+ console.warn("Error with filtering based on brand:", error);
44
+ return positions.content;
45
+ }
46
+ }
47
+
48
+ function validateSingleDesiredBrand(desiredBrand) {
49
+ if(typeof desiredBrand !== 'string' || desiredBrand.includes("[") || desiredBrand.includes("]") || desiredBrand.includes(",")){
50
+ throw new Error("Desired brand must be a single brand");
51
+ }
52
+ }
53
+
29
54
  async function saveJobsDataToCMS() {
30
55
  const positions = await fetchPositionsFromSRAPI();
31
- const desiredBrand = await getTokenFromCMS(TOKEN_NAME.DESIRED_BRAND);
32
- const sourcePositions = desiredBrand
33
- ? positions.content.filter(position => {
34
- const brand = getBrand(position.customField);
35
- if (!brand) return false;
36
- return brand === desiredBrand;
37
- })
38
- : positions.content;
56
+ const sourcePositions = await filterBasedOnBrand(positions);
39
57
 
40
58
  // bulk insert to jobs collection without descriptions first
41
59
  const jobsData = sourcePositions.map(position => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.494",
3
+ "version": "1.7.496",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {