@justair/justair-library 4.4.2-alpha → 4.4.4
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 +1 -1
- package/src/models/measurements.js +64 -1
package/package.json
CHANGED
|
@@ -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
|
{
|
|
@@ -17,6 +51,7 @@ const auditSchema = mongoose.Schema(
|
|
|
17
51
|
deletedAt: { type: Date, default: Date.now },
|
|
18
52
|
measurements: Object,
|
|
19
53
|
monitorState: String,
|
|
54
|
+
monitorSupplier: String,
|
|
20
55
|
normalizedMeasurements: Object,
|
|
21
56
|
flags: Object,
|
|
22
57
|
appliedCorrections: {
|
|
@@ -25,6 +60,7 @@ const auditSchema = mongoose.Schema(
|
|
|
25
60
|
default: {},
|
|
26
61
|
},
|
|
27
62
|
correctedNormalizedMeasurements: Object,
|
|
63
|
+
annotations: [annotationSchema], // Include annotations in audit trail
|
|
28
64
|
},
|
|
29
65
|
{
|
|
30
66
|
timestamps: true,
|
|
@@ -41,6 +77,7 @@ const measurementsSchema = mongoose.Schema(
|
|
|
41
77
|
timeUpdated: Date,
|
|
42
78
|
measurements: Object,
|
|
43
79
|
monitorState: String,
|
|
80
|
+
monitorSupplier: String,
|
|
44
81
|
normalizedMeasurements: Object,
|
|
45
82
|
flags: Object,
|
|
46
83
|
appliedCorrections: {
|
|
@@ -49,6 +86,10 @@ const measurementsSchema = mongoose.Schema(
|
|
|
49
86
|
default: {},
|
|
50
87
|
},
|
|
51
88
|
correctedNormalizedMeasurements: Object,
|
|
89
|
+
annotations: {
|
|
90
|
+
type: [annotationSchema],
|
|
91
|
+
default: [],
|
|
92
|
+
},
|
|
52
93
|
},
|
|
53
94
|
{
|
|
54
95
|
timestamps: true,
|
|
@@ -58,6 +99,12 @@ const measurementsSchema = mongoose.Schema(
|
|
|
58
99
|
measurementsSchema.index({ monitorId: 1 });
|
|
59
100
|
measurementsSchema.index({ timeUpdated: 1 });
|
|
60
101
|
|
|
102
|
+
measurementsSchema.index({
|
|
103
|
+
"annotations.measurementIdentifier": 1,
|
|
104
|
+
"annotations.timestamp": -1,
|
|
105
|
+
});
|
|
106
|
+
measurementsSchema.index({ "annotations.userId": 1 });
|
|
107
|
+
|
|
61
108
|
// Pre-hook to log single document deletions
|
|
62
109
|
measurementsSchema.pre("findOneAndDelete", async function () {
|
|
63
110
|
const docToDelete = await this.model.findOne(this.getFilter());
|
|
@@ -69,11 +116,13 @@ measurementsSchema.pre("findOneAndDelete", async function () {
|
|
|
69
116
|
timeUpdated: docToDelete.timeUpdated,
|
|
70
117
|
measurements: docToDelete.measurements,
|
|
71
118
|
monitorState: docToDelete.monitorState,
|
|
119
|
+
monitorSupplier: docToDelete.monitorSupplier,
|
|
72
120
|
normalizedMeasurements: docToDelete.normalizedMeasurements,
|
|
73
121
|
flags: docToDelete.flags,
|
|
74
122
|
appliedCorrections: docToDelete.appliedCorrections,
|
|
75
123
|
correctedNormalizedMeasurements:
|
|
76
124
|
docToDelete.correctedNormalizedMeasurements,
|
|
125
|
+
annotations: docToDelete.annotations, // Include annotations in audit
|
|
77
126
|
deletedAt: new Date(),
|
|
78
127
|
});
|
|
79
128
|
await auditLog.save();
|
|
@@ -93,10 +142,12 @@ measurementsSchema.pre("deleteMany", async function () {
|
|
|
93
142
|
timeUpdated: doc.timeUpdated,
|
|
94
143
|
measurements: doc.measurements,
|
|
95
144
|
monitorState: doc.monitorState,
|
|
145
|
+
monitorSupplier: doc.monitorSupplier,
|
|
96
146
|
normalizedMeasurements: doc.normalizedMeasurements,
|
|
97
147
|
flags: doc.flags,
|
|
98
148
|
appliedCorrections: doc.appliedCorrections,
|
|
99
149
|
correctedNormalizedMeasurements: doc.correctedNormalizedMeasurements,
|
|
150
|
+
annotations: doc.annotations, // Include annotations in audit
|
|
100
151
|
deletedAt: new Date(),
|
|
101
152
|
}));
|
|
102
153
|
|
|
@@ -117,11 +168,13 @@ measurementsSchema.pre("deleteOne", async function () {
|
|
|
117
168
|
timeUpdated: docToDelete.timeUpdated,
|
|
118
169
|
measurements: docToDelete.measurements,
|
|
119
170
|
monitorState: docToDelete.monitorState,
|
|
171
|
+
monitorSupplier: docToDelete.monitorSupplier,
|
|
120
172
|
normalizedMeasurements: docToDelete.normalizedMeasurements,
|
|
121
173
|
flags: docToDelete.flags,
|
|
122
174
|
appliedCorrections: docToDelete.appliedCorrections,
|
|
123
175
|
correctedNormalizedMeasurements:
|
|
124
176
|
docToDelete.correctedNormalizedMeasurements,
|
|
177
|
+
annotations: docToDelete.annotations, // Include annotations in audit
|
|
125
178
|
deletedAt: new Date(),
|
|
126
179
|
});
|
|
127
180
|
await auditLog.save();
|
|
@@ -139,11 +192,13 @@ measurementsSchema.pre("findOneAndUpdate", async function () {
|
|
|
139
192
|
timeUpdated: docToUpdate.timeUpdated,
|
|
140
193
|
measurements: docToUpdate.measurements,
|
|
141
194
|
monitorState: docToUpdate.monitorState,
|
|
195
|
+
monitorSupplier: docToUpdate.monitorSupplier,
|
|
142
196
|
normalizedMeasurements: docToUpdate.normalizedMeasurements,
|
|
143
197
|
flags: docToUpdate.flags,
|
|
144
198
|
appliedCorrections: docToUpdate.appliedCorrections,
|
|
145
199
|
correctedNormalizedMeasurements:
|
|
146
200
|
docToUpdate.correctedNormalizedMeasurements,
|
|
201
|
+
annotations: docToUpdate.annotations, // Include annotations in audit
|
|
147
202
|
deletedAt: null, // No deletion happening, so set it to null or undefined
|
|
148
203
|
});
|
|
149
204
|
await auditLog.save();
|
|
@@ -161,10 +216,12 @@ measurementsSchema.pre("updateMany", async function () {
|
|
|
161
216
|
timeUpdated: doc.timeUpdated,
|
|
162
217
|
measurements: doc.measurements,
|
|
163
218
|
monitorState: doc.monitorState,
|
|
219
|
+
monitorSupplier: doc.monitorSupplier,
|
|
164
220
|
normalizedMeasurements: doc.normalizedMeasurements,
|
|
165
221
|
flags: doc.flags,
|
|
166
222
|
appliedCorrections: doc.appliedCorrections,
|
|
167
223
|
correctedNormalizedMeasurements: doc.correctedNormalizedMeasurements,
|
|
224
|
+
annotations: doc.annotations, // Include annotations in audit
|
|
168
225
|
deletedAt: null, // No deletion happening
|
|
169
226
|
}));
|
|
170
227
|
|
|
@@ -174,4 +231,10 @@ measurementsSchema.pre("updateMany", async function () {
|
|
|
174
231
|
|
|
175
232
|
const Measurements = mongoose.model("Measurements", measurementsSchema);
|
|
176
233
|
|
|
177
|
-
export {
|
|
234
|
+
export {
|
|
235
|
+
measurementsSchema,
|
|
236
|
+
Measurements,
|
|
237
|
+
Audit,
|
|
238
|
+
auditSchema,
|
|
239
|
+
annotationSchema,
|
|
240
|
+
};
|