@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.
- package/README +146 -146
- package/package.json +28 -28
- package/src/config/db.js +116 -116
- package/src/config/logger.js +44 -44
- package/src/index.js +116 -116
- package/src/models/admin.js +30 -30
- package/src/models/alerts.js +221 -221
- 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/dataCompleteness.js +42 -42
- package/src/models/events.js +123 -123
- package/src/models/features.js +14 -14
- package/src/models/jobs.js +49 -49
- package/src/models/lightmonitors.js +30 -30
- package/src/models/measurements.js +269 -269
- package/src/models/monitorRequests.js +25 -25
- package/src/models/monitorSuppliers.js +21 -21
- package/src/models/monitors.js +400 -399
- package/src/models/networkMetrics.js +42 -42
- package/src/models/organizations.js +97 -97
- package/src/models/parameters.js +11 -11
- 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 +55 -55
- package/tsconfig.json +10 -10
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
-
import MonitorRequests from '../monitorRequests.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 monitor request and fetch it from the database', async () => {
|
|
27
|
-
const monitorRequestData = {
|
|
28
|
-
monitorOwnerOrg: mongoose.Types.ObjectId(), // Generate a new ObjectId for monitorOwnerOrg
|
|
29
|
-
monitorOwnerOrgName: 'Organization A',
|
|
30
|
-
monitorSharerOrg: mongoose.Types.ObjectId(), // Generate a new ObjectId for monitorSharerOrg
|
|
31
|
-
monitorSharerOrgName: 'Organization B',
|
|
32
|
-
monitorList: [
|
|
33
|
-
mongoose.Types.ObjectId(), // Generate a new ObjectId for each monitor in the list
|
|
34
|
-
mongoose.Types.ObjectId(),
|
|
35
|
-
],
|
|
36
|
-
status: 'Requested',
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// Create a new monitor request document
|
|
40
|
-
const createdMonitorRequest = await MonitorRequests.create(monitorRequestData);
|
|
41
|
-
|
|
42
|
-
// Fetch the monitor request from the database
|
|
43
|
-
const fetchedMonitorRequest = await MonitorRequests.findById(createdMonitorRequest._id);
|
|
44
|
-
|
|
45
|
-
expect(fetchedMonitorRequest).toMatchObject(monitorRequestData);
|
|
46
|
-
});
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
+
import MonitorRequests from '../monitorRequests.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 monitor request and fetch it from the database', async () => {
|
|
27
|
+
const monitorRequestData = {
|
|
28
|
+
monitorOwnerOrg: mongoose.Types.ObjectId(), // Generate a new ObjectId for monitorOwnerOrg
|
|
29
|
+
monitorOwnerOrgName: 'Organization A',
|
|
30
|
+
monitorSharerOrg: mongoose.Types.ObjectId(), // Generate a new ObjectId for monitorSharerOrg
|
|
31
|
+
monitorSharerOrgName: 'Organization B',
|
|
32
|
+
monitorList: [
|
|
33
|
+
mongoose.Types.ObjectId(), // Generate a new ObjectId for each monitor in the list
|
|
34
|
+
mongoose.Types.ObjectId(),
|
|
35
|
+
],
|
|
36
|
+
status: 'Requested',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Create a new monitor request document
|
|
40
|
+
const createdMonitorRequest = await MonitorRequests.create(monitorRequestData);
|
|
41
|
+
|
|
42
|
+
// Fetch the monitor request from the database
|
|
43
|
+
const fetchedMonitorRequest = await MonitorRequests.findById(createdMonitorRequest._id);
|
|
44
|
+
|
|
45
|
+
expect(fetchedMonitorRequest).toMatchObject(monitorRequestData);
|
|
46
|
+
});
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { Decimal128 } from 'bson';
|
|
2
|
-
import mongoose from 'mongoose';
|
|
3
|
-
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
4
|
-
import Monitors from '../monitors.js'; // Assuming this file is in the same directory
|
|
5
|
-
|
|
6
|
-
let mongoServer;
|
|
7
|
-
|
|
8
|
-
// Before running the tests, start the mock MongoDB server
|
|
9
|
-
beforeAll(async () => {
|
|
10
|
-
mongoServer = await MongoMemoryServer.create();
|
|
11
|
-
const mongoUri = mongoServer.getUri();
|
|
12
|
-
mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
// After running the tests, stop the mock MongoDB server and close the Mongoose connection
|
|
16
|
-
afterAll(async () => {
|
|
17
|
-
await mongoose.disconnect();
|
|
18
|
-
await mongoServer.stop();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// Clear the database and reset the state before each test
|
|
22
|
-
beforeEach(async () => {
|
|
23
|
-
await mongoose.connection.dropDatabase();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Sample test case
|
|
27
|
-
test('Create monitor and fetch it from the database', async () => {
|
|
28
|
-
const monitorData = {
|
|
29
|
-
monitorCode: 'ABC123',
|
|
30
|
-
monitorSupplier: 'clarity',
|
|
31
|
-
monitorIdFromSupplier: '123456',
|
|
32
|
-
measurementUpdate: new Date(),
|
|
33
|
-
monitorProperties: {
|
|
34
|
-
property1: 'value1',
|
|
35
|
-
property2: 'value2',
|
|
36
|
-
},
|
|
37
|
-
isPrivate: false,
|
|
38
|
-
monitorState: 'Collocation',
|
|
39
|
-
sponsor: mongoose.Types.ObjectId(), // Generate a new ObjectId for sponsor
|
|
40
|
-
sponsorName: 'Organization A',
|
|
41
|
-
monitorLatitude: 37.7749,
|
|
42
|
-
monitorLongitude: -122.4194,
|
|
43
|
-
location: {
|
|
44
|
-
city: 'San Francisco',
|
|
45
|
-
country: 'United States',
|
|
46
|
-
},
|
|
47
|
-
context: ['School'],
|
|
48
|
-
colocationDate: new Date(),
|
|
49
|
-
parameters: ['NO2', 'PM2.5', 'Temperature'],
|
|
50
|
-
latestPM2_5: Decimal128.fromString('10.5'), // Use Decimal128 for decimal values
|
|
51
|
-
latestAQI_PM2_5: 75,
|
|
52
|
-
isActive: true,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Create a new monitor document
|
|
56
|
-
const createdMonitor = await Monitors.create(monitorData);
|
|
57
|
-
|
|
58
|
-
// Fetch the monitor from the database
|
|
59
|
-
const fetchedMonitor = await Monitors.findById(createdMonitor._id);
|
|
60
|
-
|
|
61
|
-
expect(fetchedMonitor).toMatchObject(monitorData);
|
|
62
|
-
});
|
|
1
|
+
import { Decimal128 } from 'bson';
|
|
2
|
+
import mongoose from 'mongoose';
|
|
3
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
4
|
+
import Monitors from '../monitors.js'; // Assuming this file is in the same directory
|
|
5
|
+
|
|
6
|
+
let mongoServer;
|
|
7
|
+
|
|
8
|
+
// Before running the tests, start the mock MongoDB server
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
mongoServer = await MongoMemoryServer.create();
|
|
11
|
+
const mongoUri = mongoServer.getUri();
|
|
12
|
+
mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// After running the tests, stop the mock MongoDB server and close the Mongoose connection
|
|
16
|
+
afterAll(async () => {
|
|
17
|
+
await mongoose.disconnect();
|
|
18
|
+
await mongoServer.stop();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Clear the database and reset the state before each test
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
await mongoose.connection.dropDatabase();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Sample test case
|
|
27
|
+
test('Create monitor and fetch it from the database', async () => {
|
|
28
|
+
const monitorData = {
|
|
29
|
+
monitorCode: 'ABC123',
|
|
30
|
+
monitorSupplier: 'clarity',
|
|
31
|
+
monitorIdFromSupplier: '123456',
|
|
32
|
+
measurementUpdate: new Date(),
|
|
33
|
+
monitorProperties: {
|
|
34
|
+
property1: 'value1',
|
|
35
|
+
property2: 'value2',
|
|
36
|
+
},
|
|
37
|
+
isPrivate: false,
|
|
38
|
+
monitorState: 'Collocation',
|
|
39
|
+
sponsor: mongoose.Types.ObjectId(), // Generate a new ObjectId for sponsor
|
|
40
|
+
sponsorName: 'Organization A',
|
|
41
|
+
monitorLatitude: 37.7749,
|
|
42
|
+
monitorLongitude: -122.4194,
|
|
43
|
+
location: {
|
|
44
|
+
city: 'San Francisco',
|
|
45
|
+
country: 'United States',
|
|
46
|
+
},
|
|
47
|
+
context: ['School'],
|
|
48
|
+
colocationDate: new Date(),
|
|
49
|
+
parameters: ['NO2', 'PM2.5', 'Temperature'],
|
|
50
|
+
latestPM2_5: Decimal128.fromString('10.5'), // Use Decimal128 for decimal values
|
|
51
|
+
latestAQI_PM2_5: 75,
|
|
52
|
+
isActive: true,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Create a new monitor document
|
|
56
|
+
const createdMonitor = await Monitors.create(monitorData);
|
|
57
|
+
|
|
58
|
+
// Fetch the monitor from the database
|
|
59
|
+
const fetchedMonitor = await Monitors.findById(createdMonitor._id);
|
|
60
|
+
|
|
61
|
+
expect(fetchedMonitor).toMatchObject(monitorData);
|
|
62
|
+
});
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
-
import Organizations from '../organizations.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 organization and fetch it from the database', async () => {
|
|
27
|
-
const organizationData = {
|
|
28
|
-
name: 'Acme Corp',
|
|
29
|
-
website: 'https://www.example.com',
|
|
30
|
-
location: {
|
|
31
|
-
city: 'San Francisco',
|
|
32
|
-
country: 'United States',
|
|
33
|
-
},
|
|
34
|
-
authorized: false,
|
|
35
|
-
orgAPIKey: [{ key: 'ABC123' }],
|
|
36
|
-
orgCode: 'ACME123',
|
|
37
|
-
orgDescription: 'A sample organization',
|
|
38
|
-
orgLogo: 'https://www.example.com/logo.png',
|
|
39
|
-
connectedMonitors: [mongoose.Types.ObjectId()], // Generate a new ObjectId for each connected monitor
|
|
40
|
-
communityMessages: [{ message: 'Welcome to our community!' }],
|
|
41
|
-
isActive: true,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// Create a new organization document
|
|
45
|
-
const createdOrganization = await Organizations.create(organizationData);
|
|
46
|
-
|
|
47
|
-
// Fetch the organization from the database
|
|
48
|
-
const fetchedOrganization = await Organizations.findById(createdOrganization._id);
|
|
49
|
-
|
|
50
|
-
expect(fetchedOrganization).toMatchObject(organizationData);
|
|
51
|
-
});
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
+
import Organizations from '../organizations.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 organization and fetch it from the database', async () => {
|
|
27
|
+
const organizationData = {
|
|
28
|
+
name: 'Acme Corp',
|
|
29
|
+
website: 'https://www.example.com',
|
|
30
|
+
location: {
|
|
31
|
+
city: 'San Francisco',
|
|
32
|
+
country: 'United States',
|
|
33
|
+
},
|
|
34
|
+
authorized: false,
|
|
35
|
+
orgAPIKey: [{ key: 'ABC123' }],
|
|
36
|
+
orgCode: 'ACME123',
|
|
37
|
+
orgDescription: 'A sample organization',
|
|
38
|
+
orgLogo: 'https://www.example.com/logo.png',
|
|
39
|
+
connectedMonitors: [mongoose.Types.ObjectId()], // Generate a new ObjectId for each connected monitor
|
|
40
|
+
communityMessages: [{ message: 'Welcome to our community!' }],
|
|
41
|
+
isActive: true,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Create a new organization document
|
|
45
|
+
const createdOrganization = await Organizations.create(organizationData);
|
|
46
|
+
|
|
47
|
+
// Fetch the organization from the database
|
|
48
|
+
const fetchedOrganization = await Organizations.findById(createdOrganization._id);
|
|
49
|
+
|
|
50
|
+
expect(fetchedOrganization).toMatchObject(organizationData);
|
|
51
|
+
});
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
|
-
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
-
import Users from '../users.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 user and fetch it from the database', async () => {
|
|
27
|
-
const userData = {
|
|
28
|
-
name: 'John Doe',
|
|
29
|
-
phone: '1234567890',
|
|
30
|
-
email: 'john.doe@example.com',
|
|
31
|
-
zipCode: '12345',
|
|
32
|
-
location: {
|
|
33
|
-
city: 'San Francisco',
|
|
34
|
-
country: 'United States',
|
|
35
|
-
},
|
|
36
|
-
organizations: [mongoose.Types.ObjectId()], // Generate a new ObjectId for each organization
|
|
37
|
-
alertPhone: '9876543210',
|
|
38
|
-
alertCount: 0,
|
|
39
|
-
subscribedMonitors: [mongoose.Types.ObjectId()], // Generate a new ObjectId for each subscribed monitor
|
|
40
|
-
currentAlertMode: 'Good',
|
|
41
|
-
latestAlerts: [{ message: 'Alert 1' }],
|
|
42
|
-
optInPhone: true,
|
|
43
|
-
optInEmail: true,
|
|
44
|
-
isActive: true,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// Create a new user document
|
|
48
|
-
const createdUser = await Users.create(userData);
|
|
49
|
-
|
|
50
|
-
// Fetch the user from the database
|
|
51
|
-
const fetchedUser = await Users.findById(createdUser._id);
|
|
52
|
-
|
|
53
|
-
expect(fetchedUser).toMatchObject(userData);
|
|
54
|
-
});
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
+
import Users from '../users.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 user and fetch it from the database', async () => {
|
|
27
|
+
const userData = {
|
|
28
|
+
name: 'John Doe',
|
|
29
|
+
phone: '1234567890',
|
|
30
|
+
email: 'john.doe@example.com',
|
|
31
|
+
zipCode: '12345',
|
|
32
|
+
location: {
|
|
33
|
+
city: 'San Francisco',
|
|
34
|
+
country: 'United States',
|
|
35
|
+
},
|
|
36
|
+
organizations: [mongoose.Types.ObjectId()], // Generate a new ObjectId for each organization
|
|
37
|
+
alertPhone: '9876543210',
|
|
38
|
+
alertCount: 0,
|
|
39
|
+
subscribedMonitors: [mongoose.Types.ObjectId()], // Generate a new ObjectId for each subscribed monitor
|
|
40
|
+
currentAlertMode: 'Good',
|
|
41
|
+
latestAlerts: [{ message: 'Alert 1' }],
|
|
42
|
+
optInPhone: true,
|
|
43
|
+
optInEmail: true,
|
|
44
|
+
isActive: true,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Create a new user document
|
|
48
|
+
const createdUser = await Users.create(userData);
|
|
49
|
+
|
|
50
|
+
// Fetch the user from the database
|
|
51
|
+
const fetchedUser = await Users.findById(createdUser._id);
|
|
52
|
+
|
|
53
|
+
expect(fetchedUser).toMatchObject(userData);
|
|
54
|
+
});
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import mongoose, { Schema } from "mongoose";
|
|
2
|
-
|
|
3
|
-
const requestSchema = new Schema(
|
|
4
|
-
{
|
|
5
|
-
endpoint: String,
|
|
6
|
-
count: Number,
|
|
7
|
-
},
|
|
8
|
-
{ timestamps: true }
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
const usageMetricsSchema = mongoose.Schema(
|
|
12
|
-
{
|
|
13
|
-
apiKeyId: { type: mongoose.Schema.Types.ObjectId, ref: "ApiKey" },
|
|
14
|
-
endpoint: String,
|
|
15
|
-
response: {
|
|
16
|
-
sizeInMB: Number,
|
|
17
|
-
sizeInKB: Number,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
{ timestamps: true }
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const UsageMetrics = mongoose.model("UsageMetrics", usageMetricsSchema);
|
|
25
|
-
|
|
26
|
-
export { usageMetricsSchema, UsageMetrics };
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import mongoose, { Schema } from "mongoose";
|
|
2
|
+
|
|
3
|
+
const requestSchema = new Schema(
|
|
4
|
+
{
|
|
5
|
+
endpoint: String,
|
|
6
|
+
count: Number,
|
|
7
|
+
},
|
|
8
|
+
{ timestamps: true }
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const usageMetricsSchema = mongoose.Schema(
|
|
12
|
+
{
|
|
13
|
+
apiKeyId: { type: mongoose.Schema.Types.ObjectId, ref: "ApiKey" },
|
|
14
|
+
endpoint: String,
|
|
15
|
+
response: {
|
|
16
|
+
sizeInMB: Number,
|
|
17
|
+
sizeInKB: Number,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
},
|
|
21
|
+
{ timestamps: true }
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const UsageMetrics = mongoose.model("UsageMetrics", usageMetricsSchema);
|
|
25
|
+
|
|
26
|
+
export { usageMetricsSchema, UsageMetrics };
|
|
27
|
+
|
|
28
|
+
|
package/src/models/users.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
const usersSchema = mongoose.Schema(
|
|
4
|
-
{
|
|
5
|
-
name: String,
|
|
6
|
-
phone: String,
|
|
7
|
-
email: String,
|
|
8
|
-
zipCode: String,
|
|
9
|
-
location: [Object],
|
|
10
|
-
organizations: [{ type: mongoose.Types.ObjectId, ref: "Organizations" }],
|
|
11
|
-
alertPhone: String,
|
|
12
|
-
alertCount: { type: Number, default: 0 },
|
|
13
|
-
subscribedMonitors: [{ type: mongoose.Types.ObjectId, ref: "Monitors" }],
|
|
14
|
-
currentAlertMode: {
|
|
15
|
-
type: String,
|
|
16
|
-
enum: [
|
|
17
|
-
"Good",
|
|
18
|
-
"Unhealthy",
|
|
19
|
-
"Moderate",
|
|
20
|
-
"Unhealthy for SG",
|
|
21
|
-
"Very Unhealthy",
|
|
22
|
-
"Hazardous",
|
|
23
|
-
],
|
|
24
|
-
default: "Good",
|
|
25
|
-
},
|
|
26
|
-
latestAlerts: [Object],
|
|
27
|
-
optInPhone: { type: Boolean, default: true },
|
|
28
|
-
optInEmail: { type: Boolean, default: false },
|
|
29
|
-
isActive: { type: Boolean, default: true },
|
|
30
|
-
hasOnboarded: { type: Boolean, default: false },
|
|
31
|
-
isSharingLocation: { type: Boolean, default: false },
|
|
32
|
-
toolTips: Object,
|
|
33
|
-
alertPreferenceLevel: {
|
|
34
|
-
type: String,
|
|
35
|
-
enum: [
|
|
36
|
-
"Good",
|
|
37
|
-
"Moderate",
|
|
38
|
-
"Unhealthy for SG",
|
|
39
|
-
"Unhealthy",
|
|
40
|
-
"Very Unhealthy",
|
|
41
|
-
"Hazardous",
|
|
42
|
-
],
|
|
43
|
-
default: "Good",
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
timestamps: true,
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
usersSchema.index({ phone: 1 });
|
|
52
|
-
|
|
53
|
-
const Users = mongoose.model("Users", usersSchema);
|
|
54
|
-
|
|
55
|
-
export { usersSchema, Users };
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
const usersSchema = mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
name: String,
|
|
6
|
+
phone: String,
|
|
7
|
+
email: String,
|
|
8
|
+
zipCode: String,
|
|
9
|
+
location: [Object],
|
|
10
|
+
organizations: [{ type: mongoose.Types.ObjectId, ref: "Organizations" }],
|
|
11
|
+
alertPhone: String,
|
|
12
|
+
alertCount: { type: Number, default: 0 },
|
|
13
|
+
subscribedMonitors: [{ type: mongoose.Types.ObjectId, ref: "Monitors" }],
|
|
14
|
+
currentAlertMode: {
|
|
15
|
+
type: String,
|
|
16
|
+
enum: [
|
|
17
|
+
"Good",
|
|
18
|
+
"Unhealthy",
|
|
19
|
+
"Moderate",
|
|
20
|
+
"Unhealthy for SG",
|
|
21
|
+
"Very Unhealthy",
|
|
22
|
+
"Hazardous",
|
|
23
|
+
],
|
|
24
|
+
default: "Good",
|
|
25
|
+
},
|
|
26
|
+
latestAlerts: [Object],
|
|
27
|
+
optInPhone: { type: Boolean, default: true },
|
|
28
|
+
optInEmail: { type: Boolean, default: false },
|
|
29
|
+
isActive: { type: Boolean, default: true },
|
|
30
|
+
hasOnboarded: { type: Boolean, default: false },
|
|
31
|
+
isSharingLocation: { type: Boolean, default: false },
|
|
32
|
+
toolTips: Object,
|
|
33
|
+
alertPreferenceLevel: {
|
|
34
|
+
type: String,
|
|
35
|
+
enum: [
|
|
36
|
+
"Good",
|
|
37
|
+
"Moderate",
|
|
38
|
+
"Unhealthy for SG",
|
|
39
|
+
"Unhealthy",
|
|
40
|
+
"Very Unhealthy",
|
|
41
|
+
"Hazardous",
|
|
42
|
+
],
|
|
43
|
+
default: "Good",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
timestamps: true,
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
usersSchema.index({ phone: 1 });
|
|
52
|
+
|
|
53
|
+
const Users = mongoose.model("Users", usersSchema);
|
|
54
|
+
|
|
55
|
+
export { usersSchema, Users };
|
package/tsconfig.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": ["src/**/*"],
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"allowJs": true,
|
|
5
|
-
// Generate d.ts files
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"emitDeclarationOnly": true,
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"declarationMap": true
|
|
10
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"include": ["src/**/*"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
// Generate d.ts files
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"emitDeclarationOnly": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"declarationMap": true
|
|
10
|
+
}
|
|
11
11
|
}
|