@justair/justair-library 3.4.1 → 3.4.2
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/README +85 -85
- package/package.json +27 -27
- package/src/config/db.js +42 -42
- package/src/config/logger.js +44 -44
- package/src/index.js +95 -95
- package/src/models/admin.js +22 -22
- package/src/models/announcements.js +31 -31
- package/src/models/apiKey.js +22 -22
- package/src/models/configurations.js +17 -17
- package/src/models/contexts.js +13 -13
- package/src/models/events.js +124 -124
- package/src/models/jobs.js +40 -40
- package/src/models/lightmonitors.js +28 -28
- package/src/models/measurements.js +133 -132
- package/src/models/monitorRequests.js +25 -25
- package/src/models/monitorSuppliers.js +11 -11
- package/src/models/monitorType.js +40 -0
- package/src/models/monitors.js +217 -217
- package/src/models/organizations.js +23 -23
- package/src/models/parameters.js +11 -11
- package/src/models/qanotifications.js +32 -32
- package/src/models/referenceMonitorInfo.js +18 -18
- package/src/models/tests/admin.test.js +42 -42
- package/src/models/tests/configurations.test.js +44 -44
- package/src/models/tests/measurements.test.js +46 -46
- package/src/models/tests/monitorRequests.test.js +46 -46
- package/src/models/tests/monitors.test.js +62 -62
- package/src/models/tests/organizations.test.js +51 -51
- package/src/models/tests/users.test.js +54 -54
- package/src/models/usageMetrics.js +28 -28
- package/src/models/users.js +30 -30
- package/tsconfig.json +10 -10
|
@@ -1,132 +1,133 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
// Audit Schema
|
|
4
|
-
const auditSchema = mongoose.Schema(
|
|
5
|
-
{
|
|
6
|
-
monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
|
|
7
|
-
orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
|
|
8
|
-
timeUpdated: Date,
|
|
9
|
-
deletedAt: { type: Date, default: Date.now },
|
|
10
|
-
measurements: Object,
|
|
11
|
-
monitorState: String,
|
|
12
|
-
normalizedMeasurements: Object,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
timestamps: true,
|
|
16
|
-
}
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const Audit = mongoose.model("Audit", auditSchema);
|
|
20
|
-
|
|
21
|
-
// Measurements Schema
|
|
22
|
-
const measurementsSchema = mongoose.Schema(
|
|
23
|
-
{
|
|
24
|
-
monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
|
|
25
|
-
orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
|
|
26
|
-
timeUpdated: Date,
|
|
27
|
-
measurements: Object,
|
|
28
|
-
monitorState: String,
|
|
29
|
-
normalizedMeasurements: Object,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
measurementsSchema.index({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
// Audit Schema
|
|
4
|
+
const auditSchema = mongoose.Schema(
|
|
5
|
+
{
|
|
6
|
+
monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
|
|
7
|
+
orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
|
|
8
|
+
timeUpdated: Date,
|
|
9
|
+
deletedAt: { type: Date, default: Date.now },
|
|
10
|
+
measurements: Object,
|
|
11
|
+
monitorState: String,
|
|
12
|
+
normalizedMeasurements: Object,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
timestamps: true,
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const Audit = mongoose.model("Audit", auditSchema);
|
|
20
|
+
|
|
21
|
+
// Measurements Schema
|
|
22
|
+
const measurementsSchema = mongoose.Schema(
|
|
23
|
+
{
|
|
24
|
+
monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
|
|
25
|
+
orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
|
|
26
|
+
timeUpdated: Date,
|
|
27
|
+
measurements: Object,
|
|
28
|
+
monitorState: String,
|
|
29
|
+
normalizedMeasurements: Object,
|
|
30
|
+
flags: Object
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
timestamps: true,
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
measurementsSchema.index({ monitorId: 1 });
|
|
38
|
+
measurementsSchema.index({ timeUpdated: 1 });
|
|
39
|
+
|
|
40
|
+
// Pre-hook to log single document deletions
|
|
41
|
+
measurementsSchema.pre("findOneAndDelete", async function () {
|
|
42
|
+
const docToDelete = await this.model.findOne(this.getFilter());
|
|
43
|
+
if (docToDelete) {
|
|
44
|
+
console.log("Logging findOneAndDelete to audit", docToDelete);
|
|
45
|
+
const auditLog = new Audit({
|
|
46
|
+
monitorId: docToDelete.monitorId,
|
|
47
|
+
orgId: docToDelete.orgId,
|
|
48
|
+
timeUpdated: docToDelete.timeUpdated,
|
|
49
|
+
measurements: docToDelete.measurements,
|
|
50
|
+
monitorState: docToDelete.monitorState,
|
|
51
|
+
deletedAt: new Date(),
|
|
52
|
+
});
|
|
53
|
+
await auditLog.save();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Pre-hook to log multiple document deletions
|
|
58
|
+
measurementsSchema.pre("deleteMany", async function () {
|
|
59
|
+
console.log("deleteMany pre-hook triggered");
|
|
60
|
+
const docsToDelete = await this.model.find(this.getFilter()).lean();
|
|
61
|
+
|
|
62
|
+
if (docsToDelete.length) {
|
|
63
|
+
console.log(`Logging ${docsToDelete.length} documents to audit`);
|
|
64
|
+
const auditLogs = docsToDelete.map((doc) => ({
|
|
65
|
+
monitorId: doc.monitorId,
|
|
66
|
+
orgId: doc.orgId,
|
|
67
|
+
timeUpdated: doc.timeUpdated,
|
|
68
|
+
measurements: doc.measurements,
|
|
69
|
+
monitorState: doc.monitorState,
|
|
70
|
+
deletedAt: new Date(),
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
await Audit.insertMany(auditLogs);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Pre-hook to log a single document deletion (for deleteOne)
|
|
78
|
+
measurementsSchema.pre("deleteOne", async function () {
|
|
79
|
+
console.log("deleteOne pre-hook triggered");
|
|
80
|
+
const docToDelete = await this.model.findOne(this.getFilter()).lean();
|
|
81
|
+
|
|
82
|
+
if (docToDelete) {
|
|
83
|
+
console.log("Logging deleteOne to audit", docToDelete);
|
|
84
|
+
const auditLog = new Audit({
|
|
85
|
+
monitorId: docToDelete.monitorId,
|
|
86
|
+
orgId: docToDelete.orgId,
|
|
87
|
+
timeUpdated: docToDelete.timeUpdated,
|
|
88
|
+
measurements: docToDelete.measurements,
|
|
89
|
+
monitorState: docToDelete.monitorState,
|
|
90
|
+
deletedAt: new Date(),
|
|
91
|
+
});
|
|
92
|
+
await auditLog.save();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Pre-hook to log single document updates
|
|
97
|
+
measurementsSchema.pre("findOneAndUpdate", async function () {
|
|
98
|
+
const docToUpdate = await this.model.findOne(this.getFilter()).lean();
|
|
99
|
+
if (docToUpdate) {
|
|
100
|
+
console.log("Logging findOneAndUpdate to audit", docToUpdate);
|
|
101
|
+
const auditLog = new Audit({
|
|
102
|
+
monitorId: docToUpdate.monitorId,
|
|
103
|
+
orgId: docToUpdate.orgId,
|
|
104
|
+
timeUpdated: docToUpdate.timeUpdated,
|
|
105
|
+
measurements: docToUpdate.measurements,
|
|
106
|
+
monitorState: docToUpdate.monitorState,
|
|
107
|
+
deletedAt: null, // No deletion happening, so set it to null or undefined
|
|
108
|
+
});
|
|
109
|
+
await auditLog.save();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Pre-hook to log multiple document updates
|
|
114
|
+
measurementsSchema.pre("updateMany", async function () {
|
|
115
|
+
const docsToUpdate = await this.model.find(this.getFilter()).lean();
|
|
116
|
+
if (docsToUpdate.length) {
|
|
117
|
+
console.log(`Logging ${docsToUpdate.length} documents to audit`);
|
|
118
|
+
const auditLogs = docsToUpdate.map((doc) => ({
|
|
119
|
+
monitorId: doc.monitorId,
|
|
120
|
+
orgId: doc.orgId,
|
|
121
|
+
timeUpdated: doc.timeUpdated,
|
|
122
|
+
measurements: doc.measurements,
|
|
123
|
+
monitorState: doc.monitorState,
|
|
124
|
+
deletedAt: null, // No deletion happening
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
await Audit.insertMany(auditLogs);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const Measurements = mongoose.model("Measurements", measurementsSchema);
|
|
132
|
+
|
|
133
|
+
export { measurementsSchema, Measurements, Audit, auditSchema };
|
|
@@ -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,12 +1,12 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
const monitorSuppliersSchema = mongoose.Schema({
|
|
4
|
-
name : String
|
|
5
|
-
},
|
|
6
|
-
{
|
|
7
|
-
timestamps: true
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const MonitorSuppliers = mongoose.model("MonitorSuppliers", monitorSuppliersSchema);
|
|
11
|
-
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const monitorSuppliersSchema = mongoose.Schema({
|
|
4
|
+
name : String
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
timestamps: true
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const MonitorSuppliers = mongoose.model("MonitorSuppliers", monitorSuppliersSchema);
|
|
11
|
+
|
|
12
12
|
export {monitorSuppliersSchema, MonitorSuppliers};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const parametersEnum = [
|
|
4
|
+
"NO2",
|
|
5
|
+
"SO2",
|
|
6
|
+
"PM2.5",
|
|
7
|
+
"PM10",
|
|
8
|
+
"Temperature",
|
|
9
|
+
"Humidity",
|
|
10
|
+
"OZONE",
|
|
11
|
+
"VOC",
|
|
12
|
+
"CO",
|
|
13
|
+
"NO",
|
|
14
|
+
"PM1",
|
|
15
|
+
"WS And Direction",
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const monitorTypeSchema = mongoose.Schema(
|
|
19
|
+
{
|
|
20
|
+
model: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
supplier: {
|
|
26
|
+
type: mongoose.Types.ObjectId,
|
|
27
|
+
required: true,
|
|
28
|
+
ref: "MonitorSuppliers",
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
parameters: {
|
|
32
|
+
type: String,
|
|
33
|
+
enum: parametersEnum,
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{ timestamps: true }
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const monitorType = mongoose.model("MonitorType", monitorTypeSchema);
|