@justair/justair-library 4.0.0 → 4.1.0-beta

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": "4.0.0",
3
+ "version": "4.1.0-beta",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,5 +1,13 @@
1
1
  import mongoose from "mongoose";
2
2
 
3
+ const correctionSnapshotSchema = new mongoose.Schema(
4
+ {
5
+ equationType: String,
6
+ dateCreated: Date,
7
+ },
8
+ { _id: false } // Not generating separate _id for each correction
9
+ );
10
+
3
11
  // Audit Schema
4
12
  const auditSchema = mongoose.Schema(
5
13
  {
@@ -10,6 +18,13 @@ const auditSchema = mongoose.Schema(
10
18
  measurements: Object,
11
19
  monitorState: String,
12
20
  normalizedMeasurements: Object,
21
+ flags: Object,
22
+ appliedCorrections: {
23
+ type: Map,
24
+ of: correctionSnapshotSchema,
25
+ default: {},
26
+ },
27
+ correctedNormalizedMeasurements: Object,
13
28
  },
14
29
  {
15
30
  timestamps: true,
@@ -27,7 +42,13 @@ const measurementsSchema = mongoose.Schema(
27
42
  measurements: Object,
28
43
  monitorState: String,
29
44
  normalizedMeasurements: Object,
30
- flags: Object
45
+ flags: Object,
46
+ appliedCorrections: {
47
+ type: Map,
48
+ of: correctionSnapshotSchema,
49
+ default: {},
50
+ },
51
+ correctedNormalizedMeasurements: Object,
31
52
  },
32
53
  {
33
54
  timestamps: true,
@@ -48,6 +69,11 @@ measurementsSchema.pre("findOneAndDelete", async function () {
48
69
  timeUpdated: docToDelete.timeUpdated,
49
70
  measurements: docToDelete.measurements,
50
71
  monitorState: docToDelete.monitorState,
72
+ normalizedMeasurements: docToDelete.normalizedMeasurements,
73
+ flags: docToDelete.flags,
74
+ appliedCorrections: docToDelete.appliedCorrections,
75
+ correctedNormalizedMeasurements:
76
+ docToDelete.correctedNormalizedMeasurements,
51
77
  deletedAt: new Date(),
52
78
  });
53
79
  await auditLog.save();
@@ -67,6 +93,10 @@ measurementsSchema.pre("deleteMany", async function () {
67
93
  timeUpdated: doc.timeUpdated,
68
94
  measurements: doc.measurements,
69
95
  monitorState: doc.monitorState,
96
+ normalizedMeasurements: doc.normalizedMeasurements,
97
+ flags: doc.flags,
98
+ appliedCorrections: doc.appliedCorrections,
99
+ correctedNormalizedMeasurements: doc.correctedNormalizedMeasurements,
70
100
  deletedAt: new Date(),
71
101
  }));
72
102
 
@@ -87,6 +117,11 @@ measurementsSchema.pre("deleteOne", async function () {
87
117
  timeUpdated: docToDelete.timeUpdated,
88
118
  measurements: docToDelete.measurements,
89
119
  monitorState: docToDelete.monitorState,
120
+ normalizedMeasurements: docToDelete.normalizedMeasurements,
121
+ flags: docToDelete.flags,
122
+ appliedCorrections: docToDelete.appliedCorrections,
123
+ correctedNormalizedMeasurements:
124
+ docToDelete.correctedNormalizedMeasurements,
90
125
  deletedAt: new Date(),
91
126
  });
92
127
  await auditLog.save();
@@ -104,6 +139,11 @@ measurementsSchema.pre("findOneAndUpdate", async function () {
104
139
  timeUpdated: docToUpdate.timeUpdated,
105
140
  measurements: docToUpdate.measurements,
106
141
  monitorState: docToUpdate.monitorState,
142
+ normalizedMeasurements: docToUpdate.normalizedMeasurements,
143
+ flags: docToUpdate.flags,
144
+ appliedCorrections: docToUpdate.appliedCorrections,
145
+ correctedNormalizedMeasurements:
146
+ docToUpdate.correctedNormalizedMeasurements,
107
147
  deletedAt: null, // No deletion happening, so set it to null or undefined
108
148
  });
109
149
  await auditLog.save();
@@ -121,6 +161,10 @@ measurementsSchema.pre("updateMany", async function () {
121
161
  timeUpdated: doc.timeUpdated,
122
162
  measurements: doc.measurements,
123
163
  monitorState: doc.monitorState,
164
+ normalizedMeasurements: doc.normalizedMeasurements,
165
+ flags: doc.flags,
166
+ appliedCorrections: doc.appliedCorrections,
167
+ correctedNormalizedMeasurements: doc.correctedNormalizedMeasurements,
124
168
  deletedAt: null, // No deletion happening
125
169
  }));
126
170
 
@@ -14,6 +14,46 @@ const parametersEnum = [
14
14
  "WS And Direction",
15
15
  ];
16
16
 
17
+ const correctionSchema = mongoose.Schema(
18
+ {
19
+ equationType: {
20
+ type: String,
21
+ required: true,
22
+ },
23
+ variables: {
24
+ required: true,
25
+ type: Object,
26
+ },
27
+ dateCreated: {
28
+ type: Date,
29
+ default: Date.now,
30
+ },
31
+ },
32
+ { _id: false } // no separate _id for sub-docs
33
+ );
34
+
35
+ const correctionHistorySchema = mongoose.Schema(
36
+ {
37
+ pollutant: {
38
+ type: String,
39
+ required: true,
40
+ },
41
+ oldValue: {
42
+ type: correctionSchema,
43
+ default: undefined,
44
+ },
45
+ newValue: {
46
+ type: correctionSchema,
47
+ default: undefined,
48
+ },
49
+ changedAt: {
50
+ type: Date,
51
+ default: Date.now,
52
+ },
53
+ },
54
+ { _id: false }
55
+ );
56
+
17
57
  // Monitor Audit Schema
18
58
  const monitorAuditSchema = mongoose.Schema(
19
59
  {
@@ -28,6 +68,17 @@ const monitorAuditSchema = mongoose.Schema(
28
68
  type: { type: String, enum: ["Point"], required: true },
29
69
  coordinates: { type: [Number], required: true },
30
70
  },
71
+ parameterThresholds: Object,
72
+ corrections: {
73
+ type: Map,
74
+ of: correctionSchema,
75
+ default: {},
76
+ },
77
+ correctionHistory: {
78
+ type: [correctionHistorySchema],
79
+ default: [],
80
+ },
81
+ applyCorrections: { type: Boolean, default: false },
31
82
  },
32
83
  {
33
84
  timestamps: true,
@@ -104,6 +155,17 @@ const monitorsSchema = mongoose.Schema(
104
155
  images: [String],
105
156
  isActive: { type: Boolean, default: true },
106
157
  parameterThresholds: Object,
158
+ // A Map, keyed by pollutant (e.g. "PM2_5"), storing Correction sub-docs
159
+ corrections: {
160
+ type: Map,
161
+ of: correctionSchema,
162
+ default: {},
163
+ },
164
+ correctionHistory: {
165
+ type: [correctionHistorySchema],
166
+ default: [],
167
+ },
168
+ applyCorrections: { type: Boolean, default: false },
107
169
  },
108
170
  {
109
171
  timestamps: true,
@@ -133,6 +195,10 @@ monitorsSchema.pre("findOneAndDelete", async function () {
133
195
  docToDelete.monitorLatitude,
134
196
  ],
135
197
  },
198
+ parameterThresholds: docToDelete.parameterThresholds,
199
+ corrections: docToDelete.corrections,
200
+ correctionHistory: docToDelete.correctionHistory,
201
+ applyCorrections: docToDelete.applyCorrections,
136
202
  deletedAt: new Date(),
137
203
  });
138
204
  await auditLog.save();
@@ -156,6 +222,10 @@ monitorsSchema.pre("deleteMany", async function () {
156
222
  type: "Point",
157
223
  coordinates: [doc.monitorLongitude, doc.monitorLatitude],
158
224
  },
225
+ parameterThresholds: doc.parameterThresholds,
226
+ corrections: doc.corrections,
227
+ correctionHistory: doc.correctionHistory,
228
+ applyCorrections: doc.applyCorrections,
159
229
  deletedAt: new Date(),
160
230
  }));
161
231
 
@@ -183,6 +253,10 @@ monitorsSchema.pre("deleteOne", async function () {
183
253
  docToDelete.monitorLatitude,
184
254
  ],
185
255
  },
256
+ parameterThresholds: docToDelete.parameterThresholds,
257
+ corrections: docToDelete.corrections,
258
+ correctionHistory: docToDelete.correctionHistory,
259
+ applyCorrections: docToDelete.applyCorrections,
186
260
  deletedAt: new Date(),
187
261
  });
188
262
  await auditLog.save();
@@ -204,6 +278,10 @@ monitorsSchema.pre("updateMany", async function () {
204
278
  type: "Point",
205
279
  coordinates: [doc.monitorLongitude, doc.monitorLatitude],
206
280
  },
281
+ parameterThresholds: doc.parameterThresholds,
282
+ corrections: doc.corrections,
283
+ correctionHistory: doc.correctionHistory,
284
+ applyCorrections: doc.applyCorrections,
207
285
  deletedAt: null, // Not a deletion, so this field is null
208
286
  }));
209
287
 
@@ -1,6 +1,26 @@
1
- import mongoose from "mongoose";
1
+ import mongoose, { Schema } from "mongoose";
2
2
 
3
- const organizationsSchema = mongoose.Schema({
3
+ const correctionSchema = new Schema(
4
+ {
5
+ correctionName: String,
6
+ equationType: {
7
+ type: String,
8
+ required: true,
9
+ },
10
+ variables: {
11
+ type: Object,
12
+ required: true,
13
+ },
14
+ dateCreated: {
15
+ type: Date,
16
+ default: Date.now,
17
+ },
18
+ },
19
+ { _id: false }
20
+ );
21
+
22
+ const organizationsSchema = mongoose.Schema(
23
+ {
4
24
  name: String,
5
25
  website: String,
6
26
  location: Object,
@@ -10,15 +30,17 @@ const organizationsSchema = mongoose.Schema({
10
30
  orgDescription: String,
11
31
  orgLogo: String,
12
32
  customAlertLevels: [Object],
13
- connectedMonitors: [{ type: mongoose.Types.ObjectId, ref: 'Monitors' }],
33
+ connectedMonitors: [{ type: mongoose.Types.ObjectId, ref: "Monitors" }],
14
34
  communityMessages: [Object],
15
35
  weeklyReportData: [Object],
16
- isActive: { type: Boolean, default: true }
17
- },
18
- {
19
- timestamps: true
20
- });
36
+ isActive: { type: Boolean, default: true },
37
+ correctionRules: [correctionSchema],
38
+ },
39
+ {
40
+ timestamps: true,
41
+ }
42
+ );
21
43
 
22
- const Organizations = mongoose.model('Organizations', organizationsSchema);
44
+ const Organizations = mongoose.model("Organizations", organizationsSchema);
23
45
 
24
- export {organizationsSchema, Organizations};
46
+ export { organizationsSchema, Organizations };