@justair/justair-library 4.8.43 → 4.8.45

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.8.43",
3
+ "version": "4.8.45",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  monitorAuditSchema,
20
20
  MonitorAudit,
21
21
  parametersEnum,
22
+ deploymentTypesEnum,
22
23
  } from "./models/monitors.js";
23
24
  import { organizationsSchema, Organizations } from "./models/organizations.js";
24
25
  import {
@@ -123,6 +124,7 @@ export {
123
124
  MonitorAudit,
124
125
  monitorAuditSchema,
125
126
  parametersEnum,
127
+ deploymentTypesEnum,
126
128
  AlertsAudit,
127
129
  Alerts,
128
130
  alertsSchema,
@@ -1,4 +1,5 @@
1
1
  import mongoose from "mongoose";
2
+ import { deploymentTypesEnum } from "./monitors.js";
2
3
 
3
4
  const errorLogSchema = mongoose.Schema(
4
5
  {
@@ -35,6 +36,10 @@ const monitorSuppliersSchema = mongoose.Schema(
35
36
  latestErrorLogs: {
36
37
  type: [errorLogSchema],
37
38
  },
39
+ supportedDeploymentTypes: {
40
+ type: [String],
41
+ enum: Object.values(deploymentTypesEnum),
42
+ },
38
43
  },
39
44
  {
40
45
  timestamps: true,
@@ -22,6 +22,11 @@ const parametersEnum = [
22
22
  "H2S",
23
23
  ];
24
24
 
25
+ const deploymentTypesEnum = {
26
+ STATIONARY: "stationary",
27
+ MOBILE: "mobile",
28
+ };
29
+
25
30
  const noteSchema = mongoose.Schema({
26
31
  note: {
27
32
  type: String,
@@ -158,6 +163,7 @@ const monitorAuditSchema = mongoose.Schema(
158
163
  type: [correctionHistorySchema],
159
164
  default: [],
160
165
  },
166
+ deploymentType: String,
161
167
  },
162
168
  {
163
169
  timestamps: true,
@@ -264,6 +270,11 @@ const monitorsSchema = mongoose.Schema(
264
270
  type: [{ parameter: String, timestamp: Date, isPaused: Boolean }],
265
271
  default: [],
266
272
  },
273
+ deploymentType: {
274
+ type: String,
275
+ enum: Object.values(deploymentTypesEnum),
276
+ default: deploymentTypesEnum.STATIONARY,
277
+ },
267
278
  },
268
279
  {
269
280
  timestamps: true,
@@ -289,6 +300,9 @@ monitorsSchema.index({ parameters: 1 });
289
300
  //network metrics for anomalies
290
301
  monitorsSchema.index({ sponsor: 1, isActive: 1, monitorSupplier: 1 });
291
302
 
303
+ // Deployment type filtering
304
+ monitorsSchema.index({ deploymentType: 1 });
305
+
292
306
  // Pre-hook to log single document deletions
293
307
  monitorsSchema.pre("findOneAndDelete", async function () {
294
308
  const docToDelete = await this.model.findOne(this.getFilter()).lean();
@@ -311,6 +325,7 @@ monitorsSchema.pre("findOneAndDelete", async function () {
311
325
  corrections: docToDelete.corrections,
312
326
  correctionHistory: docToDelete.correctionHistory,
313
327
  applyCorrections: docToDelete.applyCorrections,
328
+ deploymentType: docToDelete.deploymentType,
314
329
  deletedAt: new Date(),
315
330
  });
316
331
  await auditLog.save();
@@ -338,6 +353,7 @@ monitorsSchema.pre("deleteMany", async function () {
338
353
  corrections: doc.corrections,
339
354
  correctionHistory: doc.correctionHistory,
340
355
  applyCorrections: doc.applyCorrections,
356
+ deploymentType: doc.deploymentType,
341
357
  deletedAt: new Date(),
342
358
  }));
343
359
 
@@ -369,6 +385,7 @@ monitorsSchema.pre("deleteOne", async function () {
369
385
  corrections: docToDelete.corrections,
370
386
  correctionHistory: docToDelete.correctionHistory,
371
387
  applyCorrections: docToDelete.applyCorrections,
388
+ deploymentType: docToDelete.deploymentType,
372
389
  deletedAt: new Date(),
373
390
  });
374
391
  await auditLog.save();
@@ -394,6 +411,7 @@ monitorsSchema.pre("updateMany", async function () {
394
411
  corrections: doc.corrections,
395
412
  correctionHistory: doc.correctionHistory,
396
413
  applyCorrections: doc.applyCorrections,
414
+ deploymentType: doc.deploymentType,
397
415
  deletedAt: null, // Not a deletion, so this field is null
398
416
  }));
399
417
 
@@ -404,4 +422,4 @@ monitorsSchema.pre("updateMany", async function () {
404
422
  // Create the Monitors model
405
423
  const Monitors = mongoose.model("Monitors", monitorsSchema);
406
424
 
407
- export { monitorsSchema, Monitors, monitorAuditSchema, MonitorAudit, parametersEnum };
425
+ export { monitorsSchema, Monitors, monitorAuditSchema, MonitorAudit, parametersEnum, deploymentTypesEnum };
@@ -30,6 +30,8 @@ const samplesAuditSchema = mongoose.Schema(
30
30
  upperDetectionLimit: { type: Number },
31
31
  lowerDetectionLimit: { type: Number },
32
32
  deletedAt: { type: Date, default: Date.now }, // Only populated on delete
33
+ uploadedByName: { type: String }, // Name of the user who uploaded the sample
34
+ uploadDate: { type: Date }, // Date when the sample was uploaded
33
35
  },
34
36
  {
35
37
  timestamps: true,
@@ -54,6 +56,7 @@ const samplesSchema = mongoose.Schema(
54
56
  upperDetectionLimit: { type: Number },
55
57
  lowerDetectionLimit: { type: Number },
56
58
  uploadedByName: { type: String }, // Name of the user who uploaded the sample
59
+ uploadDate: { type: Date }, // Date when the sample was uploaded
57
60
  },
58
61
  {
59
62
  timestamps: true,
@@ -64,6 +67,8 @@ const samplesSchema = mongoose.Schema(
64
67
  samplesSchema.index({ siteId: 1, periodStartDate: -1 });
65
68
  // Pollutant-based queries
66
69
  samplesSchema.index({ siteId: 1, parameterName: 1 });
70
+ // Upload history queries (show samples grouped by upload date)
71
+ samplesSchema.index({ siteId: 1, uploadDate: -1 });
67
72
 
68
73
  // Pre-hook to log single document deletions
69
74
  samplesSchema.pre("findOneAndDelete", async function () {
@@ -82,6 +87,8 @@ samplesSchema.pre("findOneAndDelete", async function () {
82
87
  upperDetectionLimit: docToDelete.upperDetectionLimit,
83
88
  lowerDetectionLimit: docToDelete.lowerDetectionLimit,
84
89
  deletedAt: new Date(),
90
+ uploadedByName: docToDelete.uploadedByName,
91
+ uploadDate: docToDelete.uploadDate,
85
92
  });
86
93
  await auditLog.save();
87
94
  }
@@ -105,6 +112,8 @@ samplesSchema.pre("deleteMany", async function () {
105
112
  upperDetectionLimit: doc.upperDetectionLimit,
106
113
  lowerDetectionLimit: doc.lowerDetectionLimit,
107
114
  deletedAt: new Date(),
115
+ uploadedByName: doc.uploadedByName,
116
+ uploadDate: doc.uploadDate,
108
117
  }));
109
118
  await SamplesAudit.insertMany(auditLogs);
110
119
  }
@@ -128,6 +137,8 @@ samplesSchema.pre("deleteOne", async function () {
128
137
  upperDetectionLimit: docToDelete.upperDetectionLimit,
129
138
  lowerDetectionLimit: docToDelete.lowerDetectionLimit,
130
139
  deletedAt: new Date(),
140
+ uploadedByName: docToDelete.uploadedByName,
141
+ uploadDate: docToDelete.uploadDate,
131
142
  });
132
143
  await auditLog.save();
133
144
  }
@@ -150,6 +161,8 @@ samplesSchema.pre("findOneAndUpdate", async function () {
150
161
  upperDetectionLimit: docToUpdate.upperDetectionLimit,
151
162
  lowerDetectionLimit: docToUpdate.lowerDetectionLimit,
152
163
  deletedAt: null,
164
+ uploadedByName: docToUpdate.uploadedByName,
165
+ uploadDate: docToUpdate.uploadDate,
153
166
  });
154
167
  await auditLog.save();
155
168
  }
@@ -172,6 +185,8 @@ samplesSchema.pre("updateMany", async function () {
172
185
  upperDetectionLimit: doc.upperDetectionLimit,
173
186
  lowerDetectionLimit: doc.lowerDetectionLimit,
174
187
  deletedAt: null,
188
+ uploadedByName: doc.uploadedByName,
189
+ uploadDate: doc.uploadDate,
175
190
  }));
176
191
  await SamplesAudit.insertMany(auditLogs);
177
192
  }