@justair/justair-library 4.8.11 → 4.8.13

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.
Files changed (35) hide show
  1. package/.github/workflows/publish.yml +28 -0
  2. package/README +146 -146
  3. package/package.json +27 -27
  4. package/src/config/db.js +116 -116
  5. package/src/config/logger.js +143 -143
  6. package/src/index.js +116 -116
  7. package/src/models/admin.js +27 -27
  8. package/src/models/alerts.js +219 -219
  9. package/src/models/announcements.js +31 -31
  10. package/src/models/apiKey.js +22 -22
  11. package/src/models/configurations.js +17 -17
  12. package/src/models/contexts.js +13 -13
  13. package/src/models/dataCompleteness.js +35 -35
  14. package/src/models/events.js +128 -128
  15. package/src/models/features.js +14 -14
  16. package/src/models/jobs.js +43 -43
  17. package/src/models/lightmonitors.js +30 -30
  18. package/src/models/measurements.js +263 -263
  19. package/src/models/monitorRequests.js +25 -25
  20. package/src/models/monitorSuppliers.js +49 -49
  21. package/src/models/monitors.js +394 -394
  22. package/src/models/networkMetrics.js +42 -42
  23. package/src/models/organizations.js +97 -97
  24. package/src/models/parameters.js +11 -11
  25. package/src/models/referenceMonitorInfo.js +18 -18
  26. package/src/models/tests/admin.test.js +42 -42
  27. package/src/models/tests/configurations.test.js +44 -44
  28. package/src/models/tests/measurements.test.js +46 -46
  29. package/src/models/tests/monitorRequests.test.js +46 -46
  30. package/src/models/tests/monitors.test.js +62 -62
  31. package/src/models/tests/organizations.test.js +51 -51
  32. package/src/models/tests/users.test.js +54 -54
  33. package/src/models/usageMetrics.js +28 -28
  34. package/src/models/users.js +55 -55
  35. package/tsconfig.json +10 -10
@@ -1,263 +1,263 @@
1
- import mongoose from "mongoose";
2
-
3
- const correctionSnapshotSchema = new mongoose.Schema(
4
- {
5
- equationType: {
6
- type: String,
7
- enum: ["custom", "linear"],
8
- required: true,
9
- },
10
- equation: {
11
- type: String,
12
- required: function () {
13
- return this.equationType === "custom";
14
- },
15
- },
16
- dateCreated: {
17
- type: Date,
18
- default: Date.now,
19
- },
20
- },
21
- { _id: false } // Not generating separate _id for each correction
22
- );
23
-
24
- // Annotation Schema
25
- const annotationSchema = new mongoose.Schema(
26
- {
27
- measurementIdentifier: {
28
- type: String,
29
- required: true,
30
- trim: true,
31
- // Examples: "PM2_5", "PM10", "NO2", "O3", etc.
32
- },
33
- comment: {
34
- type: String,
35
- required: true,
36
- trim: true,
37
- },
38
- adminId: {
39
- type: mongoose.Types.ObjectId,
40
- ref: "Admin",
41
- required: function () {
42
- return this.source === "admin";
43
- },
44
- },
45
- source: {
46
- type: String,
47
- enum: ["admin", "processing_engine"],
48
- required: true,
49
- default: "admin",
50
- },
51
- timestamp: {
52
- type: Date,
53
- default: Date.now,
54
- required: true,
55
- },
56
- },
57
- {
58
- _id: true,
59
- timestamps: false,
60
- }
61
- );
62
-
63
- // Add index for efficient querying
64
- annotationSchema.index({ measurementIdentifier: 1, timestamp: -1 });
65
-
66
- // Audit Schema
67
- const auditSchema = mongoose.Schema(
68
- {
69
- monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
70
- orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
71
- timeUpdated: Date,
72
- deletedAt: { type: Date, default: Date.now },
73
- measurements: Object,
74
- monitorState: String,
75
- monitorSupplier: String,
76
- rawNormalizedMeasurements: Object,
77
- normalizedMeasurements: Object,
78
- flags: Object,
79
- appliedCorrections: {
80
- type: Map,
81
- of: correctionSnapshotSchema,
82
- default: {},
83
- },
84
- annotations: [annotationSchema], // Include annotations in audit trail
85
- },
86
- {
87
- timestamps: true,
88
- }
89
- );
90
-
91
- const Audit = mongoose.model("Audit", auditSchema);
92
-
93
- // Measurements Schema
94
- const measurementsSchema = mongoose.Schema(
95
- {
96
- monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
97
- orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
98
- timeUpdated: Date,
99
- measurements: Object,
100
- monitorState: String,
101
- monitorSupplier: String,
102
- rawNormalizedMeasurements: Object,
103
- normalizedMeasurements: Object,
104
- flags: Object,
105
- appliedCorrections: {
106
- type: Map,
107
- of: correctionSnapshotSchema,
108
- default: {},
109
- },
110
- annotations: {
111
- type: [annotationSchema],
112
- default: [],
113
- },
114
- },
115
- {
116
- timestamps: true,
117
- }
118
- );
119
-
120
- // CRITICAL: Add compound indexes for monitorId + timeUpdated
121
- // Primary query pattern index (descending timeUpdated for latest data first)
122
- measurementsSchema.index({ monitorId: 1, timeUpdated: -1 });
123
-
124
- // Flag-based query index for filtering by monitor and flags
125
- measurementsSchema.index({ monitorId: 1, flags: 1 });
126
-
127
- // Annotation-related indexes
128
- measurementsSchema.index({
129
- "annotations.measurementIdentifier": 1,
130
- "annotations.timestamp": -1,
131
- });
132
- measurementsSchema.index({ "annotations.userId": 1 });
133
-
134
- // Pre-hook to log single document deletions
135
- measurementsSchema.pre("findOneAndDelete", async function () {
136
- const docToDelete = await this.model.findOne(this.getFilter());
137
- if (docToDelete) {
138
- console.log("Logging findOneAndDelete to audit", docToDelete);
139
- const auditLog = new Audit({
140
- monitorId: docToDelete.monitorId,
141
- orgId: docToDelete.orgId,
142
- timeUpdated: docToDelete.timeUpdated,
143
- measurements: docToDelete.measurements,
144
- monitorState: docToDelete.monitorState,
145
- monitorSupplier: docToDelete.monitorSupplier,
146
- normalizedMeasurements: docToDelete.normalizedMeasurements,
147
- rawNormalizedMeasurements: docToDelete.rawNormalizedMeasurements,
148
- flags: docToDelete.flags,
149
- appliedCorrections: docToDelete.appliedCorrections,
150
- annotations: docToDelete.annotations, // Include annotations in audit
151
- deletedAt: new Date(),
152
- });
153
- await auditLog.save();
154
- }
155
- });
156
-
157
- // Pre-hook to log multiple document deletions
158
- measurementsSchema.pre("deleteMany", async function () {
159
- console.log("deleteMany pre-hook triggered");
160
- const docsToDelete = await this.model.find(this.getFilter()).lean();
161
-
162
- if (docsToDelete.length) {
163
- console.log(`Logging ${docsToDelete.length} documents to audit`);
164
- const auditLogs = docsToDelete.map((doc) => ({
165
- monitorId: doc.monitorId,
166
- orgId: doc.orgId,
167
- timeUpdated: doc.timeUpdated,
168
- measurements: doc.measurements,
169
- monitorState: doc.monitorState,
170
- monitorSupplier: doc.monitorSupplier,
171
- normalizedMeasurements: doc.normalizedMeasurements,
172
- rawNormalizedMeasurements: doc.rawNormalizedMeasurements,
173
- flags: doc.flags,
174
- appliedCorrections: doc.appliedCorrections,
175
- annotations: doc.annotations, // Include annotations in audit
176
- deletedAt: new Date(),
177
- }));
178
-
179
- await Audit.insertMany(auditLogs);
180
- }
181
- });
182
-
183
- // Pre-hook to log a single document deletion (for deleteOne)
184
- measurementsSchema.pre("deleteOne", async function () {
185
- console.log("deleteOne pre-hook triggered");
186
- const docToDelete = await this.model.findOne(this.getFilter()).lean();
187
-
188
- if (docToDelete) {
189
- console.log("Logging deleteOne to audit", docToDelete);
190
- const auditLog = new Audit({
191
- monitorId: docToDelete.monitorId,
192
- orgId: docToDelete.orgId,
193
- timeUpdated: docToDelete.timeUpdated,
194
- measurements: docToDelete.measurements,
195
- monitorState: docToDelete.monitorState,
196
- monitorSupplier: docToDelete.monitorSupplier,
197
- normalizedMeasurements: docToDelete.normalizedMeasurements,
198
- rawNormalizedMeasurements: docToDelete.rawNormalizedMeasurements,
199
- flags: docToDelete.flags,
200
- appliedCorrections: docToDelete.appliedCorrections,
201
- annotations: docToDelete.annotations, // Include annotations in audit
202
- deletedAt: new Date(),
203
- });
204
- await auditLog.save();
205
- }
206
- });
207
-
208
- // Pre-hook to log single document updates
209
- measurementsSchema.pre("findOneAndUpdate", async function () {
210
- const docToUpdate = await this.model.findOne(this.getFilter()).lean();
211
- if (docToUpdate) {
212
- console.log("Logging findOneAndUpdate to audit", docToUpdate);
213
- const auditLog = new Audit({
214
- monitorId: docToUpdate.monitorId,
215
- orgId: docToUpdate.orgId,
216
- timeUpdated: docToUpdate.timeUpdated,
217
- measurements: docToUpdate.measurements,
218
- monitorState: docToUpdate.monitorState,
219
- monitorSupplier: docToUpdate.monitorSupplier,
220
- normalizedMeasurements: docToUpdate.normalizedMeasurements,
221
- rawNormalizedMeasurements: docToUpdate.rawNormalizedMeasurements,
222
- flags: docToUpdate.flags,
223
- appliedCorrections: docToUpdate.appliedCorrections,
224
- annotations: docToUpdate.annotations, // Include annotations in audit
225
- deletedAt: null, // No deletion happening, so set it to null or undefined
226
- });
227
- await auditLog.save();
228
- }
229
- });
230
-
231
- // Pre-hook to log multiple document updates
232
- measurementsSchema.pre("updateMany", async function () {
233
- const docsToUpdate = await this.model.find(this.getFilter()).lean();
234
- if (docsToUpdate.length) {
235
- console.log(`Logging ${docsToUpdate.length} documents to audit`);
236
- const auditLogs = docsToUpdate.map((doc) => ({
237
- monitorId: doc.monitorId,
238
- orgId: doc.orgId,
239
- timeUpdated: doc.timeUpdated,
240
- measurements: doc.measurements,
241
- monitorState: doc.monitorState,
242
- monitorSupplier: doc.monitorSupplier,
243
- normalizedMeasurements: doc.normalizedMeasurements,
244
- rawNormalizedMeasurements: doc.rawNormalizedMeasurements,
245
- flags: doc.flags,
246
- appliedCorrections: doc.appliedCorrections,
247
- annotations: doc.annotations, // Include annotations in audit
248
- deletedAt: null, // No deletion happening
249
- }));
250
-
251
- await Audit.insertMany(auditLogs);
252
- }
253
- });
254
-
255
- const Measurements = mongoose.model("Measurements", measurementsSchema);
256
-
257
- export {
258
- measurementsSchema,
259
- Measurements,
260
- Audit,
261
- auditSchema,
262
- annotationSchema,
263
- };
1
+ import mongoose from "mongoose";
2
+
3
+ const correctionSnapshotSchema = new mongoose.Schema(
4
+ {
5
+ equationType: {
6
+ type: String,
7
+ enum: ["custom", "linear"],
8
+ required: true,
9
+ },
10
+ equation: {
11
+ type: String,
12
+ required: function () {
13
+ return this.equationType === "custom";
14
+ },
15
+ },
16
+ dateCreated: {
17
+ type: Date,
18
+ default: Date.now,
19
+ },
20
+ },
21
+ { _id: false } // Not generating separate _id for each correction
22
+ );
23
+
24
+ // Annotation Schema
25
+ const annotationSchema = new mongoose.Schema(
26
+ {
27
+ measurementIdentifier: {
28
+ type: String,
29
+ required: true,
30
+ trim: true,
31
+ // Examples: "PM2_5", "PM10", "NO2", "O3", etc.
32
+ },
33
+ comment: {
34
+ type: String,
35
+ required: true,
36
+ trim: true,
37
+ },
38
+ adminId: {
39
+ type: mongoose.Types.ObjectId,
40
+ ref: "Admin",
41
+ required: function () {
42
+ return this.source === "admin";
43
+ },
44
+ },
45
+ source: {
46
+ type: String,
47
+ enum: ["admin", "processing_engine"],
48
+ required: true,
49
+ default: "admin",
50
+ },
51
+ timestamp: {
52
+ type: Date,
53
+ default: Date.now,
54
+ required: true,
55
+ },
56
+ },
57
+ {
58
+ _id: true,
59
+ timestamps: false,
60
+ }
61
+ );
62
+
63
+ // Add index for efficient querying
64
+ annotationSchema.index({ measurementIdentifier: 1, timestamp: -1 });
65
+
66
+ // Audit Schema
67
+ const auditSchema = mongoose.Schema(
68
+ {
69
+ monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
70
+ orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
71
+ timeUpdated: Date,
72
+ deletedAt: { type: Date, default: Date.now },
73
+ measurements: Object,
74
+ monitorState: String,
75
+ monitorSupplier: String,
76
+ rawNormalizedMeasurements: Object,
77
+ normalizedMeasurements: Object,
78
+ flags: Object,
79
+ appliedCorrections: {
80
+ type: Map,
81
+ of: correctionSnapshotSchema,
82
+ default: {},
83
+ },
84
+ annotations: [annotationSchema], // Include annotations in audit trail
85
+ },
86
+ {
87
+ timestamps: true,
88
+ }
89
+ );
90
+
91
+ const Audit = mongoose.model("Audit", auditSchema);
92
+
93
+ // Measurements Schema
94
+ const measurementsSchema = mongoose.Schema(
95
+ {
96
+ monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
97
+ orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
98
+ timeUpdated: Date,
99
+ measurements: Object,
100
+ monitorState: String,
101
+ monitorSupplier: String,
102
+ rawNormalizedMeasurements: Object,
103
+ normalizedMeasurements: Object,
104
+ flags: Object,
105
+ appliedCorrections: {
106
+ type: Map,
107
+ of: correctionSnapshotSchema,
108
+ default: {},
109
+ },
110
+ annotations: {
111
+ type: [annotationSchema],
112
+ default: [],
113
+ },
114
+ },
115
+ {
116
+ timestamps: true,
117
+ }
118
+ );
119
+
120
+ // CRITICAL: Add compound indexes for monitorId + timeUpdated
121
+ // Primary query pattern index (descending timeUpdated for latest data first)
122
+ measurementsSchema.index({ monitorId: 1, timeUpdated: -1 });
123
+
124
+ // Flag-based query index for filtering by monitor and flags
125
+ measurementsSchema.index({ monitorId: 1, flags: 1 });
126
+
127
+ // Annotation-related indexes
128
+ measurementsSchema.index({
129
+ "annotations.measurementIdentifier": 1,
130
+ "annotations.timestamp": -1,
131
+ });
132
+ measurementsSchema.index({ "annotations.userId": 1 });
133
+
134
+ // Pre-hook to log single document deletions
135
+ measurementsSchema.pre("findOneAndDelete", async function () {
136
+ const docToDelete = await this.model.findOne(this.getFilter());
137
+ if (docToDelete) {
138
+ console.log("Logging findOneAndDelete to audit", docToDelete);
139
+ const auditLog = new Audit({
140
+ monitorId: docToDelete.monitorId,
141
+ orgId: docToDelete.orgId,
142
+ timeUpdated: docToDelete.timeUpdated,
143
+ measurements: docToDelete.measurements,
144
+ monitorState: docToDelete.monitorState,
145
+ monitorSupplier: docToDelete.monitorSupplier,
146
+ normalizedMeasurements: docToDelete.normalizedMeasurements,
147
+ rawNormalizedMeasurements: docToDelete.rawNormalizedMeasurements,
148
+ flags: docToDelete.flags,
149
+ appliedCorrections: docToDelete.appliedCorrections,
150
+ annotations: docToDelete.annotations, // Include annotations in audit
151
+ deletedAt: new Date(),
152
+ });
153
+ await auditLog.save();
154
+ }
155
+ });
156
+
157
+ // Pre-hook to log multiple document deletions
158
+ measurementsSchema.pre("deleteMany", async function () {
159
+ console.log("deleteMany pre-hook triggered");
160
+ const docsToDelete = await this.model.find(this.getFilter()).lean();
161
+
162
+ if (docsToDelete.length) {
163
+ console.log(`Logging ${docsToDelete.length} documents to audit`);
164
+ const auditLogs = docsToDelete.map((doc) => ({
165
+ monitorId: doc.monitorId,
166
+ orgId: doc.orgId,
167
+ timeUpdated: doc.timeUpdated,
168
+ measurements: doc.measurements,
169
+ monitorState: doc.monitorState,
170
+ monitorSupplier: doc.monitorSupplier,
171
+ normalizedMeasurements: doc.normalizedMeasurements,
172
+ rawNormalizedMeasurements: doc.rawNormalizedMeasurements,
173
+ flags: doc.flags,
174
+ appliedCorrections: doc.appliedCorrections,
175
+ annotations: doc.annotations, // Include annotations in audit
176
+ deletedAt: new Date(),
177
+ }));
178
+
179
+ await Audit.insertMany(auditLogs);
180
+ }
181
+ });
182
+
183
+ // Pre-hook to log a single document deletion (for deleteOne)
184
+ measurementsSchema.pre("deleteOne", async function () {
185
+ console.log("deleteOne pre-hook triggered");
186
+ const docToDelete = await this.model.findOne(this.getFilter()).lean();
187
+
188
+ if (docToDelete) {
189
+ console.log("Logging deleteOne to audit", docToDelete);
190
+ const auditLog = new Audit({
191
+ monitorId: docToDelete.monitorId,
192
+ orgId: docToDelete.orgId,
193
+ timeUpdated: docToDelete.timeUpdated,
194
+ measurements: docToDelete.measurements,
195
+ monitorState: docToDelete.monitorState,
196
+ monitorSupplier: docToDelete.monitorSupplier,
197
+ normalizedMeasurements: docToDelete.normalizedMeasurements,
198
+ rawNormalizedMeasurements: docToDelete.rawNormalizedMeasurements,
199
+ flags: docToDelete.flags,
200
+ appliedCorrections: docToDelete.appliedCorrections,
201
+ annotations: docToDelete.annotations, // Include annotations in audit
202
+ deletedAt: new Date(),
203
+ });
204
+ await auditLog.save();
205
+ }
206
+ });
207
+
208
+ // Pre-hook to log single document updates
209
+ measurementsSchema.pre("findOneAndUpdate", async function () {
210
+ const docToUpdate = await this.model.findOne(this.getFilter()).lean();
211
+ if (docToUpdate) {
212
+ console.log("Logging findOneAndUpdate to audit", docToUpdate);
213
+ const auditLog = new Audit({
214
+ monitorId: docToUpdate.monitorId,
215
+ orgId: docToUpdate.orgId,
216
+ timeUpdated: docToUpdate.timeUpdated,
217
+ measurements: docToUpdate.measurements,
218
+ monitorState: docToUpdate.monitorState,
219
+ monitorSupplier: docToUpdate.monitorSupplier,
220
+ normalizedMeasurements: docToUpdate.normalizedMeasurements,
221
+ rawNormalizedMeasurements: docToUpdate.rawNormalizedMeasurements,
222
+ flags: docToUpdate.flags,
223
+ appliedCorrections: docToUpdate.appliedCorrections,
224
+ annotations: docToUpdate.annotations, // Include annotations in audit
225
+ deletedAt: null, // No deletion happening, so set it to null or undefined
226
+ });
227
+ await auditLog.save();
228
+ }
229
+ });
230
+
231
+ // Pre-hook to log multiple document updates
232
+ measurementsSchema.pre("updateMany", async function () {
233
+ const docsToUpdate = await this.model.find(this.getFilter()).lean();
234
+ if (docsToUpdate.length) {
235
+ console.log(`Logging ${docsToUpdate.length} documents to audit`);
236
+ const auditLogs = docsToUpdate.map((doc) => ({
237
+ monitorId: doc.monitorId,
238
+ orgId: doc.orgId,
239
+ timeUpdated: doc.timeUpdated,
240
+ measurements: doc.measurements,
241
+ monitorState: doc.monitorState,
242
+ monitorSupplier: doc.monitorSupplier,
243
+ normalizedMeasurements: doc.normalizedMeasurements,
244
+ rawNormalizedMeasurements: doc.rawNormalizedMeasurements,
245
+ flags: doc.flags,
246
+ appliedCorrections: doc.appliedCorrections,
247
+ annotations: doc.annotations, // Include annotations in audit
248
+ deletedAt: null, // No deletion happening
249
+ }));
250
+
251
+ await Audit.insertMany(auditLogs);
252
+ }
253
+ });
254
+
255
+ const Measurements = mongoose.model("Measurements", measurementsSchema);
256
+
257
+ export {
258
+ measurementsSchema,
259
+ Measurements,
260
+ Audit,
261
+ auditSchema,
262
+ annotationSchema,
263
+ };
@@ -1,25 +1,25 @@
1
- import mongoose from "mongoose";
2
-
3
- const monitorRequestsSchema = mongoose.Schema(
4
- {
5
- monitorOwnerOrg: { type: mongoose.Types.ObjectId, ref: "Organizations" },
6
- monitorOwnerOrgName: String,
7
- monitorReceiverOrg: { type: mongoose.Types.ObjectId, ref: "Organizations" },
8
- monitorReceiverOrgName: String,
9
- monitorList: [{ type: mongoose.Types.ObjectId, ref: "Monitors" }],
10
- status: {
11
- type: String,
12
- enum: ["Requested", "Approved", "Denied", "Cancel", "Deleted"],
13
- },
14
- },
15
- {
16
- timestamps: true,
17
- }
18
- );
19
-
20
- const MonitorRequests = mongoose.model(
21
- "MonitorRequests",
22
- monitorRequestsSchema
23
- );
24
-
25
- export { monitorRequestsSchema, MonitorRequests };
1
+ import mongoose from "mongoose";
2
+
3
+ const monitorRequestsSchema = mongoose.Schema(
4
+ {
5
+ monitorOwnerOrg: { type: mongoose.Types.ObjectId, ref: "Organizations" },
6
+ monitorOwnerOrgName: String,
7
+ monitorReceiverOrg: { type: mongoose.Types.ObjectId, ref: "Organizations" },
8
+ monitorReceiverOrgName: String,
9
+ monitorList: [{ type: mongoose.Types.ObjectId, ref: "Monitors" }],
10
+ status: {
11
+ type: String,
12
+ enum: ["Requested", "Approved", "Denied", "Cancel", "Deleted"],
13
+ },
14
+ },
15
+ {
16
+ timestamps: true,
17
+ }
18
+ );
19
+
20
+ const MonitorRequests = mongoose.model(
21
+ "MonitorRequests",
22
+ monitorRequestsSchema
23
+ );
24
+
25
+ export { monitorRequestsSchema, MonitorRequests };
@@ -1,49 +1,49 @@
1
- import mongoose from "mongoose";
2
-
3
- const errorLogSchema = mongoose.Schema(
4
- {
5
- error: String,
6
- org: { type: mongoose.Types.ObjectId, ref: "Organizations" },
7
- monitorsAffected: [String],
8
- timestamp: { type: Date, default: Date.now },
9
- },
10
- { _id: false }
11
- );
12
-
13
- const monitorSuppliersSchema = mongoose.Schema(
14
- {
15
- name: String,
16
- supplierTypes: [String],
17
- authenticationStructure: [String],
18
- defaultParameterThresholds: Object,
19
- defaultCompletenessThresholdCount: Number,
20
- runFrequencyMinutes: { type: Number, default: 5 },
21
- aqiServiceRunMinute: { type: Number, default: 5 },
22
- lastSuccessfulRun: Date,
23
- lastFailedRun: Date,
24
- rateLimits: [
25
- {
26
- type: {
27
- type: String,
28
- required: true,
29
- enum: ["second", "hourly", "daily", "weekly", "monthly"],
30
- },
31
- limit: { type: Number, required: true },
32
- _id: false,
33
- },
34
- ],
35
- latestErrorLogs: {
36
- type: [errorLogSchema],
37
- },
38
- },
39
- {
40
- timestamps: true,
41
- }
42
- );
43
-
44
- const MonitorSuppliers = mongoose.model(
45
- "MonitorSuppliers",
46
- monitorSuppliersSchema
47
- );
48
-
49
- export { monitorSuppliersSchema, MonitorSuppliers };
1
+ import mongoose from "mongoose";
2
+
3
+ const errorLogSchema = mongoose.Schema(
4
+ {
5
+ error: String,
6
+ org: { type: mongoose.Types.ObjectId, ref: "Organizations" },
7
+ monitorsAffected: [String],
8
+ timestamp: { type: Date, default: Date.now },
9
+ },
10
+ { _id: false }
11
+ );
12
+
13
+ const monitorSuppliersSchema = mongoose.Schema(
14
+ {
15
+ name: String,
16
+ supplierTypes: [String],
17
+ authenticationStructure: [String],
18
+ defaultParameterThresholds: Object,
19
+ defaultCompletenessThresholdCount: Number,
20
+ runFrequencyMinutes: { type: Number, default: 5 },
21
+ aqiServiceRunMinute: { type: Number, default: 5 },
22
+ lastSuccessfulRun: Date,
23
+ lastFailedRun: Date,
24
+ rateLimits: [
25
+ {
26
+ type: {
27
+ type: String,
28
+ required: true,
29
+ enum: ["second", "hourly", "daily", "weekly", "monthly"],
30
+ },
31
+ limit: { type: Number, required: true },
32
+ _id: false,
33
+ },
34
+ ],
35
+ latestErrorLogs: {
36
+ type: [errorLogSchema],
37
+ },
38
+ },
39
+ {
40
+ timestamps: true,
41
+ }
42
+ );
43
+
44
+ const MonitorSuppliers = mongoose.model(
45
+ "MonitorSuppliers",
46
+ monitorSuppliersSchema
47
+ );
48
+
49
+ export { monitorSuppliersSchema, MonitorSuppliers };