@justair/justair-library 3.3.4-golf → 3.3.4-india

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justair/justair-library",
3
- "version": "3.3.4-golf",
3
+ "version": "3.3.4-india",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -16,17 +16,32 @@ const parametersEnum = [
16
16
 
17
17
  const parameterThresholdsSchema = mongoose.Schema({
18
18
  parameter: {
19
- type: mongoose.Schema.Types.Mixed,
20
- validate: {
21
- validator: function(v) {
22
- return Object.keys(v).every(key => pollutants.includes(key)
23
- );
19
+ type: Map,
20
+ of: new mongoose.Schema({
21
+ invalid: {
22
+ max: Number,
23
+ min: Number,
24
24
  },
25
- message: props => `${props.value} is not a valid parameter threshold object`
26
- }
25
+
26
+ warning: {
27
+ max: Number,
28
+ min: Number,
29
+ },
30
+ }),
27
31
  },
28
32
  });
29
33
 
34
+ /*Ensure the parameter value is one of our valid parameters */
35
+ parameterThresholdsSchema.path('parameter').validate(function(value) {
36
+ console.log(value)
37
+ for (let key of value.keys()) {
38
+ if (!parametersEnum.includes(key)) {
39
+ return false;
40
+ }
41
+ }
42
+ return true;
43
+ }, 'Invalid parameter key');
44
+
30
45
  // Monitors Schema
31
46
  const monitorsSchema = mongoose.Schema(
32
47
  {
@@ -94,7 +109,7 @@ const monitorsSchema = mongoose.Schema(
94
109
  calculatedAverages: [Object],
95
110
  images: [String],
96
111
  isActive: { type: Boolean, default: true },
97
- parameterThresholds: { type: Object, },
112
+ parameterThresholds: { type: Map, of: parameterThresholdsSchema },
98
113
  },
99
114
  {
100
115
  timestamps: true,