@justair/justair-library 4.4.2-alpha → 4.4.3

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.4.2-alpha",
3
+ "version": "4.4.3",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -8,6 +8,40 @@ const correctionSnapshotSchema = new mongoose.Schema(
8
8
  { _id: false } // Not generating separate _id for each correction
9
9
  );
10
10
 
11
+ // Annotation Schema
12
+ const annotationSchema = new mongoose.Schema(
13
+ {
14
+ measurementIdentifier: {
15
+ type: String,
16
+ required: true,
17
+ trim: true,
18
+ // Examples: "PM2_5", "PM10", "NO2", "O3", etc.
19
+ },
20
+ comment: {
21
+ type: String,
22
+ required: true,
23
+ trim: true,
24
+ },
25
+ adminId: {
26
+ type: mongoose.Types.ObjectId,
27
+ ref: "Admin",
28
+ required: true,
29
+ },
30
+ timestamp: {
31
+ type: Date,
32
+ default: Date.now,
33
+ required: true,
34
+ },
35
+ },
36
+ {
37
+ _id: true,
38
+ timestamps: false,
39
+ }
40
+ );
41
+
42
+ // Add index for efficient querying
43
+ annotationSchema.index({ measurementIdentifier: 1, timestamp: -1 });
44
+
11
45
  // Audit Schema
12
46
  const auditSchema = mongoose.Schema(
13
47
  {
@@ -25,6 +59,7 @@ const auditSchema = mongoose.Schema(
25
59
  default: {},
26
60
  },
27
61
  correctedNormalizedMeasurements: Object,
62
+ annotations: [annotationSchema], // Include annotations in audit trail
28
63
  },
29
64
  {
30
65
  timestamps: true,
@@ -49,6 +84,10 @@ const measurementsSchema = mongoose.Schema(
49
84
  default: {},
50
85
  },
51
86
  correctedNormalizedMeasurements: Object,
87
+ annotations: {
88
+ type: [annotationSchema],
89
+ default: [],
90
+ },
52
91
  },
53
92
  {
54
93
  timestamps: true,
@@ -58,6 +97,12 @@ const measurementsSchema = mongoose.Schema(
58
97
  measurementsSchema.index({ monitorId: 1 });
59
98
  measurementsSchema.index({ timeUpdated: 1 });
60
99
 
100
+ measurementsSchema.index({
101
+ "annotations.measurementIdentifier": 1,
102
+ "annotations.timestamp": -1,
103
+ });
104
+ measurementsSchema.index({ "annotations.userId": 1 });
105
+
61
106
  // Pre-hook to log single document deletions
62
107
  measurementsSchema.pre("findOneAndDelete", async function () {
63
108
  const docToDelete = await this.model.findOne(this.getFilter());
@@ -74,6 +119,7 @@ measurementsSchema.pre("findOneAndDelete", async function () {
74
119
  appliedCorrections: docToDelete.appliedCorrections,
75
120
  correctedNormalizedMeasurements:
76
121
  docToDelete.correctedNormalizedMeasurements,
122
+ annotations: docToDelete.annotations, // Include annotations in audit
77
123
  deletedAt: new Date(),
78
124
  });
79
125
  await auditLog.save();
@@ -97,6 +143,7 @@ measurementsSchema.pre("deleteMany", async function () {
97
143
  flags: doc.flags,
98
144
  appliedCorrections: doc.appliedCorrections,
99
145
  correctedNormalizedMeasurements: doc.correctedNormalizedMeasurements,
146
+ annotations: doc.annotations, // Include annotations in audit
100
147
  deletedAt: new Date(),
101
148
  }));
102
149
 
@@ -122,6 +169,7 @@ measurementsSchema.pre("deleteOne", async function () {
122
169
  appliedCorrections: docToDelete.appliedCorrections,
123
170
  correctedNormalizedMeasurements:
124
171
  docToDelete.correctedNormalizedMeasurements,
172
+ annotations: docToDelete.annotations, // Include annotations in audit
125
173
  deletedAt: new Date(),
126
174
  });
127
175
  await auditLog.save();
@@ -144,6 +192,7 @@ measurementsSchema.pre("findOneAndUpdate", async function () {
144
192
  appliedCorrections: docToUpdate.appliedCorrections,
145
193
  correctedNormalizedMeasurements:
146
194
  docToUpdate.correctedNormalizedMeasurements,
195
+ annotations: docToUpdate.annotations, // Include annotations in audit
147
196
  deletedAt: null, // No deletion happening, so set it to null or undefined
148
197
  });
149
198
  await auditLog.save();
@@ -165,6 +214,7 @@ measurementsSchema.pre("updateMany", async function () {
165
214
  flags: doc.flags,
166
215
  appliedCorrections: doc.appliedCorrections,
167
216
  correctedNormalizedMeasurements: doc.correctedNormalizedMeasurements,
217
+ annotations: doc.annotations, // Include annotations in audit
168
218
  deletedAt: null, // No deletion happening
169
219
  }));
170
220
 
@@ -174,4 +224,10 @@ measurementsSchema.pre("updateMany", async function () {
174
224
 
175
225
  const Measurements = mongoose.model("Measurements", measurementsSchema);
176
226
 
177
- export { measurementsSchema, Measurements, Audit, auditSchema };
227
+ export {
228
+ measurementsSchema,
229
+ Measurements,
230
+ Audit,
231
+ auditSchema,
232
+ annotationSchema,
233
+ };