@justair/justair-library 4.6.2 → 4.7.1

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.6.2",
3
+ "version": "4.7.1",
4
4
  "description": "JustAir Internal Library",
5
5
 
6
6
  "main": "src/index.js",
@@ -15,7 +15,15 @@ const adminSchema = mongoose.Schema({
15
15
  timestamps: true
16
16
  });
17
17
 
18
- adminSchema.index({email: 1});
18
+ // Organization-based admin queries
19
+ adminSchema.index({ orgId: 1, isActive: 1 });
20
+ // Email-based login with active status (case-insensitive handled in app)
21
+ adminSchema.index({ email: 1, isActive: 1 });
22
+ // Permission-based queries
23
+ adminSchema.index({ orgId: 1, permissionName: 1 });
24
+
25
+ // Keep individual email index for backward compatibility
26
+ adminSchema.index({ email: 1 });
19
27
 
20
28
 
21
29
  const Admin = mongoose.model('Admin', adminSchema);
@@ -47,10 +47,19 @@ const alertsSchema = mongoose.Schema(
47
47
  }
48
48
  );
49
49
 
50
+ // Organization-based queries with timestamp ordering
51
+ alertsSchema.index({ orgId: 1, updatedAt: -1 });
52
+ // Monitor-based queries for lookups with timestamp ordering
53
+ alertsSchema.index({ monitorId: 1, updatedAt: -1 });
54
+ // Status-based filtering with organization and timestamp
55
+ alertsSchema.index({ orgId: 1, status: 1, updatedAt: -1 });
56
+ // Alert configuration matching - already optimal
57
+ alertsSchema.index({ alertConfigurationId: 1 });
58
+
59
+ // Keep individual indexes for backward compatibility
50
60
  alertsSchema.index({ orgId: 1 });
51
61
  alertsSchema.index({ monitorId: 1 });
52
62
  alertsSchema.index({ type: 1 });
53
- alertsSchema.index({ alertConfigurationId: 1 });
54
63
 
55
64
  const alertsAuditSchema = mongoose.Schema(
56
65
  {
@@ -44,6 +44,12 @@ const eventsSchema = mongoose.Schema(
44
44
  }
45
45
  );
46
46
 
47
+ // Primary lookup pattern from monitors - for $lookup operations
48
+ eventsSchema.index({ monitorId: 1, createdAt: -1 });
49
+ // Date range filtering index
50
+ eventsSchema.index({ monitorId: 1, updatedAt: -1 });
51
+
52
+ // Keep individual indexes for other query patterns
47
53
  eventsSchema.index({ monitorId: 1 });
48
54
  eventsSchema.index({ parameter: 1 });
49
55
 
@@ -32,6 +32,15 @@ const jobsSchema = mongoose.Schema(
32
32
 
33
33
  const Jobs = mongoose.model("Jobs", jobsSchema);
34
34
 
35
+ // Requestor-based queries with category filtering
36
+ jobsSchema.index({ requestorId: 1, category: 1 });
37
+ // Exclude specific categories efficiently with timestamp ordering
38
+ jobsSchema.index({ requestorId: 1, category: 1, createdAt: -1 });
39
+ // Monitor-based job lookups (if monitorId field exists in resourceMetaData)
40
+ // Note: This may need to be adjusted based on actual schema structure
41
+ // jobsSchema.index({ "resourceMetaData.monitorId": 1, updatedAt: -1 });
42
+
43
+ // Keep individual indexes for backward compatibility
35
44
  jobsSchema.index({ requestorId: 1 });
36
45
  jobsSchema.index({ createdAt: 1 });
37
46
  jobsSchema.index({ category: 1 });
@@ -96,11 +96,16 @@ const measurementsSchema = mongoose.Schema(
96
96
  }
97
97
  );
98
98
 
99
- // CRITICAL: Add compound index for monitorId + timeUpdated
100
- // This significantly improves performance for date range queries on specific monitors
99
+ // CRITICAL: Add compound indexes for monitorId + timeUpdated
100
+ // Primary query pattern index (descending timeUpdated for latest data first)
101
101
  measurementsSchema.index({ monitorId: 1, timeUpdated: -1 });
102
+ // Date range query index (ascending timeUpdated for range queries)
103
+ measurementsSchema.index({ monitorId: 1, timeUpdated: 1 });
102
104
 
103
- // Keep the individual indexes as they may still be useful for other queries
105
+ // Flag-based query index for filtering by monitor and flags
106
+ measurementsSchema.index({ monitorId: 1, flags: 1 });
107
+
108
+ // Keep the individual indexes as they may still be useful for other queries
104
109
  measurementsSchema.index({ monitorId: 1 });
105
110
  measurementsSchema.index({ timeUpdated: 1 });
106
111
 
@@ -12,6 +12,7 @@ const parametersEnum = [
12
12
  "NO",
13
13
  "PM1",
14
14
  "WS And Direction",
15
+ "DP",
15
16
  ];
16
17
 
17
18
  const noteSchema = mongoose.Schema({
@@ -207,7 +208,26 @@ const monitorsSchema = mongoose.Schema(
207
208
  }
208
209
  );
209
210
 
211
+ // Geographic queries - already exists
210
212
  monitorsSchema.index({ gpsLocation: "2dsphere" });
213
+
214
+ // Sponsor-based queries
215
+ monitorsSchema.index({ sponsor: 1, isPrivate: 1, isActive: 1 });
216
+
217
+ // Location-based filtering
218
+ monitorsSchema.index({ "location.city": 1, "location.state": 1 });
219
+ monitorsSchema.index({ "location.neighborhood": 1 });
220
+ monitorsSchema.index({ "location.county": 1 });
221
+
222
+ // Query parameter filtering
223
+ monitorsSchema.index({ monitorSupplier: 1, monitorState: 1 });
224
+ monitorsSchema.index({ context: 1 });
225
+ monitorsSchema.index({ parameters: 1 });
226
+
227
+ // Monitor lookups by supplier
228
+ monitorsSchema.index({ sponsor: 1, monitorSupplier: 1 });
229
+
230
+ // Keep existing single-field indexes for backward compatibility
211
231
  monitorsSchema.index({ monitorSupplier: 1 });
212
232
  monitorsSchema.index({ monitorIdFromSupplier: 1 });
213
233
  monitorsSchema.index({ monitorState: 1 });
@@ -72,6 +72,13 @@ const organizationsSchema = mongoose.Schema(
72
72
  }
73
73
  );
74
74
 
75
+ // Name-based sorting index
76
+ organizationsSchema.index({ name: 1 });
77
+ // Connected monitors array queries
78
+ organizationsSchema.index({ connectedMonitors: 1 });
79
+ // Alert configuration queries
80
+ organizationsSchema.index({ _id: 1, "alertConfigurations.isActive": 1 });
81
+
75
82
  const Organizations = mongoose.model("Organizations", organizationsSchema);
76
83
 
77
84
  export { organizationsSchema, Organizations };