@justair/justair-library 3.3.1 → 3.3.2-alpha

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.
@@ -1,95 +1,95 @@
1
- import mongoose from "mongoose";
2
-
3
- const monitorsSchema = mongoose.Schema(
4
- {
5
- monitorCode: String,
6
- //keep up to date with diff manufacturers
7
- monitorSupplier: {
8
- type: String,
9
- enum: [
10
- "clarity",
11
- "aeroqual",
12
- "purple air",
13
- "reference monitor",
14
- "earthview",
15
- "sensit",
16
- "blue sky",
17
- "aq mesh",
18
- "quant aq",
19
- ],
20
- },
21
- monitorType: String,
22
- monitorIdFromSupplier: String,
23
- measurementUpdate: Date,
24
- monitorProperties: Object,
25
- isPrivate: { type: Boolean, default: false },
26
- monitorState: {
27
- type: String,
28
- enum: ["Collocation", "Deployed", "Maintenance", "Pending Deployment"],
29
- },
30
- monitorStateHistory: [Object],
31
- monitorAlertStatus: {
32
- type: String,
33
- enum: [
34
- "Good",
35
- "Moderate",
36
- "Unhealthy for SG",
37
- "Unhealthy",
38
- "Very Unhealthy",
39
- "Hazardous",
40
- "Bad",
41
- ],
42
- default: "Good",
43
- },
44
- sponsor: { type: mongoose.Types.ObjectId, ref: "Organizations" },
45
- sponsorName: String,
46
- monitorLatitude: Number,
47
- monitorLongitude: Number,
48
- gpsLocation: {
49
- type: { type: String, enul: ["Point"], required: true },
50
- coordinates: { type: [Number], required: true },
51
- },
52
- location: Object, //copied over from associated org
53
- context: [String],
54
- colocationDate: Date,
55
- deploymentDate: Date,
56
- subscriptionDate: Date,
57
- parameters: [
58
- {
59
- type: String,
60
- enum: [
61
- "NO2",
62
- "SO2",
63
- "PM2.5",
64
- "PM10",
65
- "Temperature",
66
- "Humidity",
67
- "OZONE",
68
- "VOC",
69
- "CO",
70
- "NO",
71
- "PM1",
72
- "WS And Direction",
73
- ],
74
- },
75
- ],
76
- latestPM2_5: Number,
77
- latestAQI_PM2_5: Number,
78
- notes: [Object],
79
- calculatedAverages: [Object],
80
- images: [String],
81
- isActive: { type: Boolean, default: true },
82
- },
83
- {
84
- timestamps: true,
85
- }
86
- );
87
-
88
- monitorsSchema.index({ gpsLocation: "2dsphere" });
89
- monitorsSchema.index({ monitorSupplier: 1 });
90
- monitorsSchema.index({ monitorIdFromSupplier: 1 });
91
- monitorsSchema.index({ monitorState: 1 });
92
-
93
- const Monitors = mongoose.model("Monitors", monitorsSchema);
94
-
95
- export { monitorsSchema, Monitors };
1
+ import mongoose from "mongoose";
2
+
3
+ const monitorsSchema = mongoose.Schema(
4
+ {
5
+ monitorCode: String,
6
+ //keep up to date with diff manufacturers
7
+ monitorSupplier: {
8
+ type: String,
9
+ enum: [
10
+ "clarity",
11
+ "aeroqual",
12
+ "purple air",
13
+ "reference monitor",
14
+ "earthview",
15
+ "sensit",
16
+ "blue sky",
17
+ "aq mesh",
18
+ "quant aq",
19
+ ],
20
+ },
21
+ monitorType: String,
22
+ monitorIdFromSupplier: String,
23
+ measurementUpdate: Date,
24
+ monitorProperties: Object,
25
+ isPrivate: { type: Boolean, default: false },
26
+ monitorState: {
27
+ type: String,
28
+ enum: ["Collocation", "Deployed", "Maintenance", "Pending Deployment"],
29
+ },
30
+ monitorStateHistory: [Object],
31
+ monitorAlertStatus: {
32
+ type: String,
33
+ enum: [
34
+ "Good",
35
+ "Moderate",
36
+ "Unhealthy for SG",
37
+ "Unhealthy",
38
+ "Very Unhealthy",
39
+ "Hazardous",
40
+ "Bad",
41
+ ],
42
+ default: "Good",
43
+ },
44
+ sponsor: { type: mongoose.Types.ObjectId, ref: "Organizations" },
45
+ sponsorName: String,
46
+ monitorLatitude: Number,
47
+ monitorLongitude: Number,
48
+ gpsLocation: {
49
+ type: { type: String, enul: ["Point"], required: true },
50
+ coordinates: { type: [Number], required: true },
51
+ },
52
+ location: Object, //copied over from associated org
53
+ context: [String],
54
+ colocationDate: Date,
55
+ deploymentDate: Date,
56
+ subscriptionDate: Date,
57
+ parameters: [
58
+ {
59
+ type: String,
60
+ enum: [
61
+ "NO2",
62
+ "SO2",
63
+ "PM2.5",
64
+ "PM10",
65
+ "Temperature",
66
+ "Humidity",
67
+ "OZONE",
68
+ "VOC",
69
+ "CO",
70
+ "NO",
71
+ "PM1",
72
+ "WS And Direction",
73
+ ],
74
+ },
75
+ ],
76
+ latestPM2_5: Number,
77
+ latestAQI_PM2_5: Number,
78
+ notes: [Object],
79
+ calculatedAverages: [Object],
80
+ images: [String],
81
+ isActive: { type: Boolean, default: true },
82
+ },
83
+ {
84
+ timestamps: true,
85
+ }
86
+ );
87
+
88
+ monitorsSchema.index({ gpsLocation: "2dsphere" });
89
+ monitorsSchema.index({ monitorSupplier: 1 });
90
+ monitorsSchema.index({ monitorIdFromSupplier: 1 });
91
+ monitorsSchema.index({ monitorState: 1 });
92
+
93
+ const Monitors = mongoose.model("Monitors", monitorsSchema);
94
+
95
+ export { monitorsSchema, Monitors };
@@ -1,24 +1,24 @@
1
- import mongoose from "mongoose";
2
-
3
- const organizationsSchema = mongoose.Schema({
4
- name: String,
5
- website: String,
6
- location: Object,
7
- authorized: { type: Boolean, default: false },
8
- orgAPIKey: [Object],
9
- orgCode: String,
10
- orgDescription: String,
11
- orgLogo: String,
12
- customAlertLevels: [Object],
13
- connectedMonitors: [{ type: mongoose.Types.ObjectId, ref: 'Monitors' }],
14
- communityMessages: [Object],
15
- weeklyReportData: [Object],
16
- isActive: { type: Boolean, default: true }
17
- },
18
- {
19
- timestamps: true
20
- });
21
-
22
- const Organizations = mongoose.model('Organizations', organizationsSchema);
23
-
1
+ import mongoose from "mongoose";
2
+
3
+ const organizationsSchema = mongoose.Schema({
4
+ name: String,
5
+ website: String,
6
+ location: Object,
7
+ authorized: { type: Boolean, default: false },
8
+ orgAPIKey: [Object],
9
+ orgCode: String,
10
+ orgDescription: String,
11
+ orgLogo: String,
12
+ customAlertLevels: [Object],
13
+ connectedMonitors: [{ type: mongoose.Types.ObjectId, ref: 'Monitors' }],
14
+ communityMessages: [Object],
15
+ weeklyReportData: [Object],
16
+ isActive: { type: Boolean, default: true }
17
+ },
18
+ {
19
+ timestamps: true
20
+ });
21
+
22
+ const Organizations = mongoose.model('Organizations', organizationsSchema);
23
+
24
24
  export {organizationsSchema, Organizations};
@@ -1,12 +1,12 @@
1
- import mongoose from "mongoose";
2
-
3
- const parametersSchema = mongoose.Schema({
4
- name: String
5
- },
6
- {
7
- timestamps: true
8
- });
9
-
10
- const Parameters = mongoose.model("Parameters", parametersSchema);
11
-
1
+ import mongoose from "mongoose";
2
+
3
+ const parametersSchema = mongoose.Schema({
4
+ name: String
5
+ },
6
+ {
7
+ timestamps: true
8
+ });
9
+
10
+ const Parameters = mongoose.model("Parameters", parametersSchema);
11
+
12
12
  export {parametersSchema, Parameters};
@@ -1,29 +1,29 @@
1
- import mongoose from "mongoose";
2
-
3
- const qaNotificationsSchema = mongoose.Schema(
4
- {
5
- monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
6
- issue: String,
7
- reportedAt: Date,
8
- reportedBy: String,
9
- resolvedAt: Date,
10
- resolvedBy: String,
11
- resolution: String,
12
- statusHistory: [Object],
13
- type: String,
14
- status: {
15
- type: String,
16
- enum: ["Open", "Resolved", "Cancelled", "Needs Review"],
17
- },
18
- },
19
- {
20
- timestamps: true,
21
- }
22
- );
23
-
24
- const QANotifications = mongoose.model(
25
- "QANotifications",
26
- qaNotificationsSchema
27
- );
28
-
29
- export { qaNotificationsSchema, QANotifications };
1
+ import mongoose from "mongoose";
2
+
3
+ const qaNotificationsSchema = mongoose.Schema(
4
+ {
5
+ monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
6
+ issue: String,
7
+ reportedAt: Date,
8
+ reportedBy: String,
9
+ resolvedAt: Date,
10
+ resolvedBy: String,
11
+ resolution: String,
12
+ statusHistory: [Object],
13
+ type: String,
14
+ status: {
15
+ type: String,
16
+ enum: ["Open", "Resolved", "Cancelled", "Needs Review"],
17
+ },
18
+ },
19
+ {
20
+ timestamps: true,
21
+ }
22
+ );
23
+
24
+ const QANotifications = mongoose.model(
25
+ "QANotifications",
26
+ qaNotificationsSchema
27
+ );
28
+
29
+ export { qaNotificationsSchema, QANotifications };
@@ -1,19 +1,19 @@
1
- import mongoose from 'mongoose';
2
-
3
- const referenceMonitorInfoSchema = mongoose.Schema({
4
- bboxStartLat: String,
5
- bboxStartLong: String,
6
- bboxEndLat: String,
7
- bboxEndLong: String,
8
- parameters: String,
9
- sponsor: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
10
- location: Object,
11
- isActive: { type: Boolean, default: true },
12
- context: [String]
13
- }, {
14
- timestamps: true
15
- });
16
-
17
- const ReferenceMonitorInfo = mongoose.model('ReferenceMonitorInfo', referenceMonitorInfoSchema);
18
-
1
+ import mongoose from 'mongoose';
2
+
3
+ const referenceMonitorInfoSchema = mongoose.Schema({
4
+ bboxStartLat: String,
5
+ bboxStartLong: String,
6
+ bboxEndLat: String,
7
+ bboxEndLong: String,
8
+ parameters: String,
9
+ sponsor: { type: mongoose.Types.ObjectId, ref: 'Organizations' },
10
+ location: Object,
11
+ isActive: { type: Boolean, default: true },
12
+ context: [String]
13
+ }, {
14
+ timestamps: true
15
+ });
16
+
17
+ const ReferenceMonitorInfo = mongoose.model('ReferenceMonitorInfo', referenceMonitorInfoSchema);
18
+
19
19
  export {referenceMonitorInfoSchema, ReferenceMonitorInfo};
@@ -1,42 +1,42 @@
1
- import mongoose from 'mongoose';
2
- import { MongoMemoryServer } from 'mongodb-memory-server';
3
- import Admin from '../admins.js'; // Assuming this file is in the same directory
4
-
5
- let mongoServer;
6
-
7
- // Before running the tests, start the mock MongoDB server
8
- beforeAll(async () => {
9
- mongoServer = await MongoMemoryServer.create();
10
- const mongoUri = mongoServer.getUri();
11
- mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12
- });
13
-
14
- // After running the tests, stop the mock MongoDB server and close the Mongoose connection
15
- afterAll(async () => {
16
- await mongoose.disconnect();
17
- await mongoServer.stop();
18
- });
19
-
20
- // Clear the database and reset the state before each test
21
- beforeEach(async () => {
22
- await mongoose.connection.dropDatabase();
23
- });
24
-
25
- // Sample test case
26
- test('Create admin and fetch it from the database', async () => {
27
- const adminData = {
28
- name: 'John Doe',
29
- phone: '1234567890',
30
- email: 'john@example.com',
31
- password: 'password123',
32
- orgId: mongoose.Types.ObjectId(), // Generate a new ObjectId for orgId
33
- };
34
-
35
- // Create a new admin document
36
- const createdAdmin = await Admin.create(adminData);
37
-
38
- // Fetch the admin from the database
39
- const fetchedAdmin = await Admin.findById(createdAdmin._id);
40
-
41
- expect(fetchedAdmin).toMatchObject(adminData);
42
- });
1
+ import mongoose from 'mongoose';
2
+ import { MongoMemoryServer } from 'mongodb-memory-server';
3
+ import Admin from '../admins.js'; // Assuming this file is in the same directory
4
+
5
+ let mongoServer;
6
+
7
+ // Before running the tests, start the mock MongoDB server
8
+ beforeAll(async () => {
9
+ mongoServer = await MongoMemoryServer.create();
10
+ const mongoUri = mongoServer.getUri();
11
+ mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12
+ });
13
+
14
+ // After running the tests, stop the mock MongoDB server and close the Mongoose connection
15
+ afterAll(async () => {
16
+ await mongoose.disconnect();
17
+ await mongoServer.stop();
18
+ });
19
+
20
+ // Clear the database and reset the state before each test
21
+ beforeEach(async () => {
22
+ await mongoose.connection.dropDatabase();
23
+ });
24
+
25
+ // Sample test case
26
+ test('Create admin and fetch it from the database', async () => {
27
+ const adminData = {
28
+ name: 'John Doe',
29
+ phone: '1234567890',
30
+ email: 'john@example.com',
31
+ password: 'password123',
32
+ orgId: mongoose.Types.ObjectId(), // Generate a new ObjectId for orgId
33
+ };
34
+
35
+ // Create a new admin document
36
+ const createdAdmin = await Admin.create(adminData);
37
+
38
+ // Fetch the admin from the database
39
+ const fetchedAdmin = await Admin.findById(createdAdmin._id);
40
+
41
+ expect(fetchedAdmin).toMatchObject(adminData);
42
+ });
@@ -1,44 +1,44 @@
1
- import mongoose from 'mongoose';
2
- import { MongoMemoryServer } from 'mongodb-memory-server';
3
- import Configurations from '../configurations.js'; // Assuming this file is in the same directory
4
-
5
- let mongoServer;
6
-
7
- // Before running the tests, start the mock MongoDB server
8
- beforeAll(async () => {
9
- mongoServer = await MongoMemoryServer.create();
10
- const mongoUri = mongoServer.getUri();
11
- mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12
- });
13
-
14
- // After running the tests, stop the mock MongoDB server and close the Mongoose connection
15
- afterAll(async () => {
16
- await mongoose.disconnect();
17
- await mongoServer.stop();
18
- });
19
-
20
- // Clear the database and reset the state before each test
21
- beforeEach(async () => {
22
- await mongoose.connection.dropDatabase();
23
- });
24
-
25
- // Sample test case
26
- test('Create configuration and fetch it from the database', async () => {
27
- const configurationData = {
28
- type: 'flag',
29
- name: 'FeatureA',
30
- properties: {
31
- enabled: true,
32
- percentage: 50,
33
- },
34
- isActive: true,
35
- };
36
-
37
- // Create a new configuration document
38
- const createdConfiguration = await Configurations.create(configurationData);
39
-
40
- // Fetch the configuration from the database
41
- const fetchedConfiguration = await Configurations.findById(createdConfiguration._id);
42
-
43
- expect(fetchedConfiguration).toMatchObject(configurationData);
44
- });
1
+ import mongoose from 'mongoose';
2
+ import { MongoMemoryServer } from 'mongodb-memory-server';
3
+ import Configurations from '../configurations.js'; // Assuming this file is in the same directory
4
+
5
+ let mongoServer;
6
+
7
+ // Before running the tests, start the mock MongoDB server
8
+ beforeAll(async () => {
9
+ mongoServer = await MongoMemoryServer.create();
10
+ const mongoUri = mongoServer.getUri();
11
+ mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12
+ });
13
+
14
+ // After running the tests, stop the mock MongoDB server and close the Mongoose connection
15
+ afterAll(async () => {
16
+ await mongoose.disconnect();
17
+ await mongoServer.stop();
18
+ });
19
+
20
+ // Clear the database and reset the state before each test
21
+ beforeEach(async () => {
22
+ await mongoose.connection.dropDatabase();
23
+ });
24
+
25
+ // Sample test case
26
+ test('Create configuration and fetch it from the database', async () => {
27
+ const configurationData = {
28
+ type: 'flag',
29
+ name: 'FeatureA',
30
+ properties: {
31
+ enabled: true,
32
+ percentage: 50,
33
+ },
34
+ isActive: true,
35
+ };
36
+
37
+ // Create a new configuration document
38
+ const createdConfiguration = await Configurations.create(configurationData);
39
+
40
+ // Fetch the configuration from the database
41
+ const fetchedConfiguration = await Configurations.findById(createdConfiguration._id);
42
+
43
+ expect(fetchedConfiguration).toMatchObject(configurationData);
44
+ });
@@ -1,46 +1,46 @@
1
- import mongoose from 'mongoose';
2
- import { MongoMemoryServer } from 'mongodb-memory-server';
3
- import Measurements from '../measurements.js'; // Assuming this file is in the same directory
4
-
5
- let mongoServer;
6
-
7
- // Before running the tests, start the mock MongoDB server
8
- beforeAll(async () => {
9
- mongoServer = await MongoMemoryServer.create();
10
- const mongoUri = mongoServer.getUri();
11
- mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12
- });
13
-
14
- // After running the tests, stop the mock MongoDB server and close the Mongoose connection
15
- afterAll(async () => {
16
- await mongoose.disconnect();
17
- await mongoServer.stop();
18
- });
19
-
20
- // Clear the database and reset the state before each test
21
- beforeEach(async () => {
22
- await mongoose.connection.dropDatabase();
23
- });
24
-
25
- // Sample test case
26
- test('Create measurement and fetch it from the database', async () => {
27
- const measurementData = {
28
- monitorId: mongoose.Types.ObjectId(), // Generate a new ObjectId for monitorId
29
- orgId: mongoose.Types.ObjectId(), // Generate a new ObjectId for orgId
30
- timeUpdated: new Date(),
31
- measurements: {
32
- temperature: 25,
33
- humidity: 60,
34
- },
35
- alert: 'Good',
36
- alertMessage: 'High temperature detected',
37
- };
38
-
39
- // Create a new measurement document
40
- const createdMeasurement = await Measurements.create(measurementData);
41
-
42
- // Fetch the measurement from the database
43
- const fetchedMeasurement = await Measurements.findById(createdMeasurement._id);
44
-
45
- expect(fetchedMeasurement).toMatchObject(measurementData);
46
- });
1
+ import mongoose from 'mongoose';
2
+ import { MongoMemoryServer } from 'mongodb-memory-server';
3
+ import Measurements from '../measurements.js'; // Assuming this file is in the same directory
4
+
5
+ let mongoServer;
6
+
7
+ // Before running the tests, start the mock MongoDB server
8
+ beforeAll(async () => {
9
+ mongoServer = await MongoMemoryServer.create();
10
+ const mongoUri = mongoServer.getUri();
11
+ mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
12
+ });
13
+
14
+ // After running the tests, stop the mock MongoDB server and close the Mongoose connection
15
+ afterAll(async () => {
16
+ await mongoose.disconnect();
17
+ await mongoServer.stop();
18
+ });
19
+
20
+ // Clear the database and reset the state before each test
21
+ beforeEach(async () => {
22
+ await mongoose.connection.dropDatabase();
23
+ });
24
+
25
+ // Sample test case
26
+ test('Create measurement and fetch it from the database', async () => {
27
+ const measurementData = {
28
+ monitorId: mongoose.Types.ObjectId(), // Generate a new ObjectId for monitorId
29
+ orgId: mongoose.Types.ObjectId(), // Generate a new ObjectId for orgId
30
+ timeUpdated: new Date(),
31
+ measurements: {
32
+ temperature: 25,
33
+ humidity: 60,
34
+ },
35
+ alert: 'Good',
36
+ alertMessage: 'High temperature detected',
37
+ };
38
+
39
+ // Create a new measurement document
40
+ const createdMeasurement = await Measurements.create(measurementData);
41
+
42
+ // Fetch the measurement from the database
43
+ const fetchedMeasurement = await Measurements.findById(createdMeasurement._id);
44
+
45
+ expect(fetchedMeasurement).toMatchObject(measurementData);
46
+ });