@justair/justair-library 4.7.21 → 4.7.22

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,43 +1,43 @@
1
- import mongoose from "mongoose";
2
-
3
- const networkMetricsSchema = mongoose.Schema({
4
- monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
5
- orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
6
- parameter: String,
7
- parameterValue: Number,
8
- networkMean: Number,
9
- networkMonitorCount: Number,
10
- percentDeviationFromMean: Number,
11
- measurementsStartTime: Date,
12
- measurementsEndTime: Date,
13
- flags: Object
14
- }, { timestamps: true });
15
-
16
- networkMetricsSchema.index({
17
- monitorId: 1,
18
- measurementsStartTime: -1,
19
- flags: 1
20
- });
21
-
22
- networkMetricsSchema.index({
23
- parameter: 1,
24
- measurementsStartTime: 1,
25
- orgId: 1,
26
- monitorId: 1
27
- });
28
-
29
- networkMetricsSchema.index({
30
- measurementsStartTime: -1,
31
- measurementsEndTime: -1,
32
- flags: 1
33
- });
34
-
35
- networkMetricsSchema.index({
36
- orgId: 1,
37
- parameter: 1,
38
- measurementsStartTime: -1
39
- });
40
-
41
- const NetworkMetrics = mongoose.model("NetworkMetrics", networkMetricsSchema);
42
-
1
+ import mongoose from "mongoose";
2
+
3
+ const networkMetricsSchema = mongoose.Schema({
4
+ monitorId: { type: mongoose.Types.ObjectId, ref: "Monitors" },
5
+ orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
6
+ parameter: String,
7
+ parameterValue: Number,
8
+ networkMean: Number,
9
+ networkMonitorCount: Number,
10
+ percentDeviationFromMean: Number,
11
+ measurementsStartTime: Date,
12
+ measurementsEndTime: Date,
13
+ flags: Object
14
+ }, { timestamps: true });
15
+
16
+ networkMetricsSchema.index({
17
+ monitorId: 1,
18
+ measurementsStartTime: -1,
19
+ flags: 1
20
+ });
21
+
22
+ networkMetricsSchema.index({
23
+ parameter: 1,
24
+ measurementsStartTime: 1,
25
+ orgId: 1,
26
+ monitorId: 1
27
+ });
28
+
29
+ networkMetricsSchema.index({
30
+ measurementsStartTime: -1,
31
+ measurementsEndTime: -1,
32
+ flags: 1
33
+ });
34
+
35
+ networkMetricsSchema.index({
36
+ orgId: 1,
37
+ parameter: 1,
38
+ measurementsStartTime: -1
39
+ });
40
+
41
+ const NetworkMetrics = mongoose.model("NetworkMetrics", networkMetricsSchema);
42
+
43
43
  export { networkMetricsSchema, NetworkMetrics };
@@ -1,97 +1,97 @@
1
- import mongoose, { Schema } from "mongoose";
2
-
3
- const alertSchema = new Schema({
4
- type: {
5
- type: String,
6
- enum: ["Data Review"],
7
- },
8
- flagType: String,
9
- metadata: Object,
10
- frequency: Object,
11
- communicationType: [String],
12
- recipients: [
13
- {
14
- type: mongoose.Types.ObjectId,
15
- ref: "Admin",
16
- },
17
- ],
18
- isActive: {
19
- type: Boolean,
20
- default: true,
21
- },
22
- });
23
-
24
- const correctionSchema = new Schema(
25
- {
26
- correctionName: String,
27
- equationType: {
28
- type: String,
29
- required: true,
30
- },
31
- equation: {
32
- type: String,
33
- required: function () {
34
- return this.equationType === 'custom';
35
- },
36
- },
37
- context: {
38
- type: String,
39
- enum: ["field", "colocation"],
40
- required: false,
41
- },
42
- variables: {
43
- required: function () {
44
- return this.equationType === 'linear';
45
- },
46
- type: Object,
47
- },
48
- dateCreated: {
49
- type: Date,
50
- default: Date.now,
51
- },
52
- },
53
- { _id: false }
54
- );
55
-
56
- const featureSchema = new Schema({
57
- featureName: String,
58
- dateAdded: {
59
- type: Date,
60
- default: Date.now,
61
- },
62
- });
63
-
64
- const organizationsSchema = mongoose.Schema(
65
- {
66
- name: String,
67
- website: String,
68
- location: Object,
69
- authorized: { type: Boolean, default: false },
70
- orgAPIKey: [Object],
71
- orgCode: String,
72
- orgDescription: String,
73
- orgLogo: String,
74
- customAlertLevels: [Object],
75
- connectedMonitors: [{ type: mongoose.Types.ObjectId, ref: "Monitors" }],
76
- communityMessages: [Object],
77
- weeklyReportData: [Object],
78
- isActive: { type: Boolean, default: true },
79
- correctionRules: [correctionSchema],
80
- alertConfigurations: [alertSchema],
81
- features: [featureSchema],
82
- },
83
- {
84
- timestamps: true,
85
- }
86
- );
87
-
88
- // Name-based sorting index
89
- organizationsSchema.index({ name: 1 });
90
- // Connected monitors array queries
91
- organizationsSchema.index({ connectedMonitors: 1 });
92
- // Alert configuration queries
93
- organizationsSchema.index({ _id: 1, "alertConfigurations.isActive": 1 });
94
-
95
- const Organizations = mongoose.model("Organizations", organizationsSchema);
96
-
97
- export { organizationsSchema, Organizations };
1
+ import mongoose, { Schema } from "mongoose";
2
+
3
+ const alertSchema = new Schema({
4
+ type: {
5
+ type: String,
6
+ enum: ["Data Review"],
7
+ },
8
+ flagType: String,
9
+ metadata: Object,
10
+ frequency: Object,
11
+ communicationType: [String],
12
+ recipients: [
13
+ {
14
+ type: mongoose.Types.ObjectId,
15
+ ref: "Admin",
16
+ },
17
+ ],
18
+ isActive: {
19
+ type: Boolean,
20
+ default: true,
21
+ },
22
+ });
23
+
24
+ const correctionSchema = new Schema(
25
+ {
26
+ correctionName: String,
27
+ equationType: {
28
+ type: String,
29
+ required: true,
30
+ },
31
+ equation: {
32
+ type: String,
33
+ required: function () {
34
+ return this.equationType === 'custom';
35
+ },
36
+ },
37
+ context: {
38
+ type: String,
39
+ enum: ["field", "colocation"],
40
+ required: false,
41
+ },
42
+ variables: {
43
+ required: function () {
44
+ return this.equationType === 'linear';
45
+ },
46
+ type: Object,
47
+ },
48
+ dateCreated: {
49
+ type: Date,
50
+ default: Date.now,
51
+ },
52
+ },
53
+ { _id: false }
54
+ );
55
+
56
+ const featureSchema = new Schema({
57
+ featureName: String,
58
+ dateAdded: {
59
+ type: Date,
60
+ default: Date.now,
61
+ },
62
+ });
63
+
64
+ const organizationsSchema = mongoose.Schema(
65
+ {
66
+ name: String,
67
+ website: String,
68
+ location: Object,
69
+ authorized: { type: Boolean, default: false },
70
+ orgAPIKey: [Object],
71
+ orgCode: String,
72
+ orgDescription: String,
73
+ orgLogo: String,
74
+ customAlertLevels: [Object],
75
+ connectedMonitors: [{ type: mongoose.Types.ObjectId, ref: "Monitors" }],
76
+ communityMessages: [Object],
77
+ weeklyReportData: [Object],
78
+ isActive: { type: Boolean, default: true },
79
+ correctionRules: [correctionSchema],
80
+ alertConfigurations: [alertSchema],
81
+ features: [featureSchema],
82
+ },
83
+ {
84
+ timestamps: true,
85
+ }
86
+ );
87
+
88
+ // Name-based sorting index
89
+ organizationsSchema.index({ name: 1 });
90
+ // Connected monitors array queries
91
+ organizationsSchema.index({ connectedMonitors: 1 });
92
+ // Alert configuration queries
93
+ organizationsSchema.index({ _id: 1, "alertConfigurations.isActive": 1 });
94
+
95
+ const Organizations = mongoose.model("Organizations", organizationsSchema);
96
+
97
+ 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,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
+ });