tabletcommand-backend-models 7.4.104 → 7.4.106
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/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/models/department.js +10 -0
- package/build/models/department.js.map +1 -1
- package/build/models/global-settings.js +11 -0
- package/build/models/global-settings.js.map +1 -1
- package/build/models/watchduty-event.js +124 -0
- package/build/models/watchduty-event.js.map +1 -0
- package/build/test/0index.js +1 -0
- package/build/test/0index.js.map +1 -1
- package/build/test/department.js +2 -0
- package/build/test/department.js.map +1 -1
- package/build/test/global-settings.js +4 -1
- package/build/test/global-settings.js.map +1 -1
- package/build/test/mock.js +28 -0
- package/build/test/mock.js.map +1 -1
- package/build/test/watchduty-event.js +153 -0
- package/build/test/watchduty-event.js.map +1 -0
- package/build/types/watchduty-event.js +3 -0
- package/build/types/watchduty-event.js.map +1 -0
- package/definitions/index.d.ts +6 -0
- package/definitions/index.d.ts.map +1 -1
- package/definitions/models/department.d.ts.map +1 -1
- package/definitions/models/global-settings.d.ts.map +1 -1
- package/definitions/models/watchduty-event.d.ts +13 -0
- package/definitions/models/watchduty-event.d.ts.map +1 -0
- package/definitions/test/mock.d.ts +25 -0
- package/definitions/test/mock.d.ts.map +1 -1
- package/definitions/test/watchduty-event.d.ts +2 -0
- package/definitions/test/watchduty-event.d.ts.map +1 -0
- package/definitions/types/department.d.ts +5 -0
- package/definitions/types/department.d.ts.map +1 -1
- package/definitions/types/global-settings.d.ts +4 -0
- package/definitions/types/global-settings.d.ts.map +1 -1
- package/definitions/types/watchduty-event.d.ts +29 -0
- package/definitions/types/watchduty-event.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/models/department.ts +11 -0
- package/src/models/global-settings.ts +13 -0
- package/src/models/watchduty-event.ts +135 -0
- package/src/test/0index.ts +1 -0
- package/src/test/department.ts +2 -0
- package/src/test/global-settings.ts +4 -0
- package/src/test/mock.ts +29 -0
- package/src/test/watchduty-event.ts +163 -0
- package/src/types/department.ts +6 -0
- package/src/types/global-settings.ts +8 -0
- package/src/types/watchduty-event.ts +36 -0
- package/LICENSE +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tabletcommand-backend-models",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.106",
|
|
4
4
|
"description": "Tablet Command Backend Models",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint src",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"test": "tsx --test --test-concurrency=1 --test-reporter=spec src/test/*.ts"
|
|
9
9
|
},
|
|
10
10
|
"author": "Marius Ursache <marius@tabletcommand.com>",
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "UNLICENSED",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git://github.com/TabletCommand/tabletcommand-backend-models.git"
|
package/src/index.ts
CHANGED
|
@@ -88,6 +88,7 @@ async function wireModels(mongoose: MongooseModule) {
|
|
|
88
88
|
UserDevice: await getModel(import("./models/user-device")),
|
|
89
89
|
UserRegistration: await getModel(import("./models/user-registration")),
|
|
90
90
|
ValidationReport: await getModel(import("./models/validation-report")),
|
|
91
|
+
WatchDutyEvent: await getModel(import("./models/watchduty-event")),
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -154,6 +155,7 @@ export { User, UserModel } from "./models/user";
|
|
|
154
155
|
export { UserDevice, UserDeviceModel } from "./models/user-device";
|
|
155
156
|
export { UserRegistration, UserRegistrationModel } from "./models/user-registration";
|
|
156
157
|
export { ValidationReport, ValidationReportModel } from "./models/validation-report";
|
|
158
|
+
export { WatchDutyEvent, WatchDutyEventModel } from "./models/watchduty-event";
|
|
157
159
|
|
|
158
160
|
export * from "./helpers";
|
|
159
161
|
export { IntegrationTypes } from "./types/department";
|
package/src/models/department.ts
CHANGED
|
@@ -2288,6 +2288,17 @@ export default async function DepartmentModule(mongoose: MongooseModule) {
|
|
|
2288
2288
|
default: 45000,
|
|
2289
2289
|
},
|
|
2290
2290
|
},
|
|
2291
|
+
|
|
2292
|
+
watchDuty: {
|
|
2293
|
+
enabled: {
|
|
2294
|
+
type: Boolean,
|
|
2295
|
+
default: false,
|
|
2296
|
+
},
|
|
2297
|
+
visible: {
|
|
2298
|
+
type: Boolean,
|
|
2299
|
+
default: false,
|
|
2300
|
+
},
|
|
2301
|
+
},
|
|
2291
2302
|
activeUserCount: {
|
|
2292
2303
|
type: Number,
|
|
2293
2304
|
default: 0,
|
|
@@ -5,6 +5,7 @@ import { Model } from "mongoose";
|
|
|
5
5
|
import {
|
|
6
6
|
ArcGISKeyType,
|
|
7
7
|
GlobalSettingsType,
|
|
8
|
+
WatchDutySyncType,
|
|
8
9
|
ZonehavenTokenType,
|
|
9
10
|
} from "../types/global-settings";
|
|
10
11
|
import { EncryptedDataType } from "../types/common";
|
|
@@ -58,6 +59,15 @@ export default async function GlobalSettingsModule(mongoose: MongooseModule) {
|
|
|
58
59
|
id: false,
|
|
59
60
|
});
|
|
60
61
|
|
|
62
|
+
const WatchDutySync = new Schema<WatchDutySyncType>({
|
|
63
|
+
lastModifiedAt: {
|
|
64
|
+
type: Date,
|
|
65
|
+
},
|
|
66
|
+
}, {
|
|
67
|
+
_id: false,
|
|
68
|
+
id: false,
|
|
69
|
+
});
|
|
70
|
+
|
|
61
71
|
const modelSchema = new Schema<GlobalSettingsType>({
|
|
62
72
|
_id: {
|
|
63
73
|
type: Schema.Types.ObjectId,
|
|
@@ -74,6 +84,9 @@ export default async function GlobalSettingsModule(mongoose: MongooseModule) {
|
|
|
74
84
|
zonehavenToken: {
|
|
75
85
|
type: ZonehavenToken,
|
|
76
86
|
},
|
|
87
|
+
watchDutySync: {
|
|
88
|
+
type: WatchDutySync,
|
|
89
|
+
},
|
|
77
90
|
updatedAt: {
|
|
78
91
|
type: Date,
|
|
79
92
|
},
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Model } from "mongoose";
|
|
2
|
+
import {
|
|
3
|
+
MongooseModule,
|
|
4
|
+
currentDate,
|
|
5
|
+
} from "../helpers";
|
|
6
|
+
import { GeoPointSchema } from "./schema/geojson";
|
|
7
|
+
import { WatchDutyEventType, WatchDutyRegionType } from "../types/watchduty-event";
|
|
8
|
+
|
|
9
|
+
export interface WatchDutyEvent extends WatchDutyEventType { }
|
|
10
|
+
|
|
11
|
+
export default async function WatchDutyEventModule(mongoose: MongooseModule) {
|
|
12
|
+
const { Schema } = mongoose;
|
|
13
|
+
const GeoJSONPoint = GeoPointSchema(mongoose);
|
|
14
|
+
|
|
15
|
+
const WatchDutyRegion = new Schema<WatchDutyRegionType>({
|
|
16
|
+
name: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: "",
|
|
19
|
+
},
|
|
20
|
+
state: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: "",
|
|
23
|
+
},
|
|
24
|
+
}, {
|
|
25
|
+
_id: false,
|
|
26
|
+
id: false,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const modelSchema = new Schema<WatchDutyEventType>({
|
|
30
|
+
_id: {
|
|
31
|
+
type: Schema.Types.ObjectId,
|
|
32
|
+
auto: true,
|
|
33
|
+
},
|
|
34
|
+
watchDutyId: {
|
|
35
|
+
type: Number,
|
|
36
|
+
required: true,
|
|
37
|
+
},
|
|
38
|
+
name: {
|
|
39
|
+
type: String,
|
|
40
|
+
default: "",
|
|
41
|
+
},
|
|
42
|
+
description: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: "",
|
|
45
|
+
},
|
|
46
|
+
geoEventType: {
|
|
47
|
+
type: String,
|
|
48
|
+
default: "",
|
|
49
|
+
},
|
|
50
|
+
locationGeoJSON: {
|
|
51
|
+
type: GeoJSONPoint,
|
|
52
|
+
default: null,
|
|
53
|
+
},
|
|
54
|
+
address: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: "",
|
|
57
|
+
},
|
|
58
|
+
isPrescribed: {
|
|
59
|
+
type: Boolean,
|
|
60
|
+
default: false,
|
|
61
|
+
},
|
|
62
|
+
areaSquareMeters: {
|
|
63
|
+
type: Number,
|
|
64
|
+
default: null,
|
|
65
|
+
},
|
|
66
|
+
containment: {
|
|
67
|
+
type: Number,
|
|
68
|
+
default: null,
|
|
69
|
+
},
|
|
70
|
+
evacuationOrders: {
|
|
71
|
+
type: String,
|
|
72
|
+
default: "",
|
|
73
|
+
},
|
|
74
|
+
evacuationWarnings: {
|
|
75
|
+
type: String,
|
|
76
|
+
default: "",
|
|
77
|
+
},
|
|
78
|
+
evacuationAdvisories: {
|
|
79
|
+
type: String,
|
|
80
|
+
default: "",
|
|
81
|
+
},
|
|
82
|
+
evacuationShelterInPlace: {
|
|
83
|
+
type: String,
|
|
84
|
+
default: "",
|
|
85
|
+
},
|
|
86
|
+
regions: {
|
|
87
|
+
type: [WatchDutyRegion],
|
|
88
|
+
default: [],
|
|
89
|
+
},
|
|
90
|
+
active: {
|
|
91
|
+
type: Boolean,
|
|
92
|
+
default: true,
|
|
93
|
+
},
|
|
94
|
+
watchDutyCreatedAt: {
|
|
95
|
+
type: Date,
|
|
96
|
+
required: true,
|
|
97
|
+
},
|
|
98
|
+
watchDutyModifiedAt: {
|
|
99
|
+
type: Date,
|
|
100
|
+
required: true,
|
|
101
|
+
},
|
|
102
|
+
created: {
|
|
103
|
+
type: Date,
|
|
104
|
+
default: currentDate,
|
|
105
|
+
},
|
|
106
|
+
modified: {
|
|
107
|
+
type: Date,
|
|
108
|
+
default: currentDate,
|
|
109
|
+
},
|
|
110
|
+
}, {
|
|
111
|
+
autoIndex: false,
|
|
112
|
+
timestamps: {
|
|
113
|
+
createdAt: "created",
|
|
114
|
+
updatedAt: "modified",
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
modelSchema.index({
|
|
119
|
+
watchDutyId: 1,
|
|
120
|
+
}, {
|
|
121
|
+
name: "watchDutyId_1_unique",
|
|
122
|
+
unique: true,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
modelSchema.index({
|
|
126
|
+
active: 1,
|
|
127
|
+
modified: 1,
|
|
128
|
+
}, {
|
|
129
|
+
name: "active_1_modified_1",
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return mongoose.model<WatchDutyEvent>("WatchDutyEvent", modelSchema, "massive_watchduty_event", { overwriteModels: true });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface WatchDutyEventModel extends Model<WatchDutyEvent> { }
|
package/src/test/0index.ts
CHANGED
|
@@ -77,5 +77,6 @@ describe(" Models", function() {
|
|
|
77
77
|
assert.isFunction(models.UserDevice, "Missing UserDevice");
|
|
78
78
|
assert.isFunction(models.UserRegistration, "Missing UserRegistration");
|
|
79
79
|
assert.isFunction(models.ValidationReport, "Missing ValidationReport");
|
|
80
|
+
assert.isFunction(models.WatchDutyEvent, "Missing WatchDutyEvent");
|
|
80
81
|
});
|
|
81
82
|
});
|
package/src/test/department.ts
CHANGED
|
@@ -134,6 +134,8 @@ describe("Department", function () {
|
|
|
134
134
|
assert.equal(sut.timeZone, testItem.timeZone);
|
|
135
135
|
assert.equal(sut.webDisclaimer.message, testItem.webDisclaimer?.message);
|
|
136
136
|
assert.equal(sut.webDisclaimer.enabled, testItem.webDisclaimer?.enabled);
|
|
137
|
+
assert.isFalse(sut.watchDuty.enabled);
|
|
138
|
+
assert.isFalse(sut.watchDuty.visible);
|
|
137
139
|
});
|
|
138
140
|
|
|
139
141
|
it("saves SOAP forwarding connection properties", async function () {
|
|
@@ -49,5 +49,9 @@ describe("GlobalSettings", function() {
|
|
|
49
49
|
assert.equal(sut.zonehavenToken?.expireAt?.toISOString(), "2025-12-12T01:02:03.000Z");
|
|
50
50
|
assert.equal(sut.zonehavenToken?.token, testItem.zonehavenToken?.token);
|
|
51
51
|
assert.equal(sut.zonehavenToken?.referer, testItem.zonehavenToken?.referer);
|
|
52
|
+
|
|
53
|
+
assert.isObject(sut.watchDutySync);
|
|
54
|
+
assert.isTrue(isDate(sut.watchDutySync.lastModifiedAt));
|
|
55
|
+
assert.equal(sut.watchDutySync?.lastModifiedAt?.toISOString(), "2025-11-11T04:05:06.000Z");
|
|
52
56
|
});
|
|
53
57
|
});
|
package/src/test/mock.ts
CHANGED
|
@@ -996,6 +996,34 @@ export default function mockModule(dependencies: { mongoose: Mongoose; }) {
|
|
|
996
996
|
expireAt: new Date("2025-12-12T01:02:03.000Z"),
|
|
997
997
|
referer: "tabletcommand.com",
|
|
998
998
|
},
|
|
999
|
+
watchDutySync: {
|
|
1000
|
+
lastModifiedAt: new Date("2025-11-11T04:05:06.000Z"),
|
|
1001
|
+
},
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
const watchDutyEvent = {
|
|
1005
|
+
watchDutyId: 123456,
|
|
1006
|
+
name: "Line Fire",
|
|
1007
|
+
description: "Vegetation fire off Highway 38",
|
|
1008
|
+
geoEventType: "wildfire",
|
|
1009
|
+
locationGeoJSON: {
|
|
1010
|
+
type: "Point",
|
|
1011
|
+
coordinates: [-117.1234, 34.1234],
|
|
1012
|
+
},
|
|
1013
|
+
address: "Highway 38, Angelus Oaks, CA",
|
|
1014
|
+
isPrescribed: false,
|
|
1015
|
+
areaSquareMeters: 5060594,
|
|
1016
|
+
containment: 42,
|
|
1017
|
+
evacuationOrders: "Zone A, Zone B",
|
|
1018
|
+
evacuationWarnings: "Zone C",
|
|
1019
|
+
evacuationAdvisories: "Zone D",
|
|
1020
|
+
evacuationShelterInPlace: "Zone E",
|
|
1021
|
+
regions: [
|
|
1022
|
+
{ name: "San Bernardino County", state: "CA" },
|
|
1023
|
+
],
|
|
1024
|
+
active: true,
|
|
1025
|
+
watchDutyCreatedAt: new Date("2025-08-01T10:00:00.000Z"),
|
|
1026
|
+
watchDutyModifiedAt: new Date("2025-08-02T11:00:00.000Z"),
|
|
999
1027
|
};
|
|
1000
1028
|
|
|
1001
1029
|
const audioStreamAuthentication = {
|
|
@@ -1682,5 +1710,6 @@ export default function mockModule(dependencies: { mongoose: Mongoose; }) {
|
|
|
1682
1710
|
userDevice,
|
|
1683
1711
|
userRegistration,
|
|
1684
1712
|
validationReport,
|
|
1713
|
+
watchDutyEvent,
|
|
1685
1714
|
};
|
|
1686
1715
|
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
3
|
+
import * as m from "../index";
|
|
4
|
+
import * as config from "./config";
|
|
5
|
+
import mockModule from "./mock";
|
|
6
|
+
|
|
7
|
+
describe("WatchDutyEvent", function() {
|
|
8
|
+
let models: m.BackendModels, mongoose: m.MongooseModule;
|
|
9
|
+
let testItem: ReturnType<typeof mockModule>["watchDutyEvent"];
|
|
10
|
+
|
|
11
|
+
beforeEach(async function() {
|
|
12
|
+
const c = await m.connect(config.url);
|
|
13
|
+
models = c.models;
|
|
14
|
+
mongoose = c.mongoose;
|
|
15
|
+
testItem = mockModule({ mongoose }).watchDutyEvent;
|
|
16
|
+
await models.WatchDutyEvent.syncIndexes();
|
|
17
|
+
});
|
|
18
|
+
afterEach(async function() {
|
|
19
|
+
await models.WatchDutyEvent.deleteMany({});
|
|
20
|
+
await mongoose.disconnect();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("is saved and reads back every field", async function() {
|
|
24
|
+
const sut = await new models.WatchDutyEvent(testItem).save();
|
|
25
|
+
|
|
26
|
+
assert.isNotNull(sut._id);
|
|
27
|
+
assert.equal(sut.watchDutyId, testItem.watchDutyId);
|
|
28
|
+
assert.equal(sut.name, testItem.name);
|
|
29
|
+
assert.equal(sut.description, testItem.description);
|
|
30
|
+
assert.equal(sut.geoEventType, testItem.geoEventType);
|
|
31
|
+
assert.equal(sut.locationGeoJSON?.type, "Point");
|
|
32
|
+
assert.equal(sut.locationGeoJSON?.coordinates[0], testItem.locationGeoJSON.coordinates[0]);
|
|
33
|
+
assert.equal(sut.locationGeoJSON?.coordinates[1], testItem.locationGeoJSON.coordinates[1]);
|
|
34
|
+
assert.equal(sut.address, testItem.address);
|
|
35
|
+
assert.isFalse(sut.isPrescribed);
|
|
36
|
+
assert.equal(sut.areaSquareMeters, testItem.areaSquareMeters);
|
|
37
|
+
assert.equal(sut.containment, testItem.containment);
|
|
38
|
+
assert.equal(sut.evacuationOrders, testItem.evacuationOrders);
|
|
39
|
+
assert.equal(sut.evacuationWarnings, testItem.evacuationWarnings);
|
|
40
|
+
assert.equal(sut.evacuationAdvisories, testItem.evacuationAdvisories);
|
|
41
|
+
assert.equal(sut.evacuationShelterInPlace, testItem.evacuationShelterInPlace);
|
|
42
|
+
assert.equal(sut.regions.length, 1);
|
|
43
|
+
assert.equal(sut.regions[0]?.name, testItem.regions[0]?.name);
|
|
44
|
+
assert.equal(sut.regions[0]?.state, testItem.regions[0]?.state);
|
|
45
|
+
assert.isTrue(sut.active);
|
|
46
|
+
assert.equal(sut.watchDutyCreatedAt.toISOString(), testItem.watchDutyCreatedAt.toISOString());
|
|
47
|
+
assert.equal(sut.watchDutyModifiedAt.toISOString(), testItem.watchDutyModifiedAt.toISOString());
|
|
48
|
+
assert.instanceOf(sut.created, Date);
|
|
49
|
+
assert.instanceOf(sut.modified, Date);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("defaults optional fields", async function() {
|
|
53
|
+
const sut = await new models.WatchDutyEvent({
|
|
54
|
+
watchDutyId: 654321,
|
|
55
|
+
watchDutyCreatedAt: new Date(),
|
|
56
|
+
watchDutyModifiedAt: new Date(),
|
|
57
|
+
}).save();
|
|
58
|
+
|
|
59
|
+
assert.equal(sut.name, "");
|
|
60
|
+
assert.equal(sut.description, "");
|
|
61
|
+
assert.equal(sut.geoEventType, "");
|
|
62
|
+
assert.isNull(sut.locationGeoJSON);
|
|
63
|
+
assert.equal(sut.address, "");
|
|
64
|
+
assert.isFalse(sut.isPrescribed);
|
|
65
|
+
assert.isNull(sut.areaSquareMeters);
|
|
66
|
+
assert.isNull(sut.containment);
|
|
67
|
+
assert.equal(sut.evacuationOrders, "");
|
|
68
|
+
assert.equal(sut.evacuationWarnings, "");
|
|
69
|
+
assert.equal(sut.evacuationAdvisories, "");
|
|
70
|
+
assert.equal(sut.evacuationShelterInPlace, "");
|
|
71
|
+
assert.deepEqual(sut.regions, []);
|
|
72
|
+
assert.isTrue(sut.active);
|
|
73
|
+
assert.instanceOf(sut.created, Date);
|
|
74
|
+
assert.instanceOf(sut.modified, Date);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// timestamps defaults createdAt to true, which would store an undeclared createdAt field.
|
|
78
|
+
it("stores no timestamp field outside the schema", async function() {
|
|
79
|
+
await new models.WatchDutyEvent({
|
|
80
|
+
watchDutyId: 333,
|
|
81
|
+
watchDutyCreatedAt: new Date(),
|
|
82
|
+
watchDutyModifiedAt: new Date(),
|
|
83
|
+
}).save();
|
|
84
|
+
|
|
85
|
+
const raw = await models.WatchDutyEvent.collection.findOne({ watchDutyId: 333 });
|
|
86
|
+
assert.isNotNull(raw);
|
|
87
|
+
assert.notProperty(raw, "createdAt");
|
|
88
|
+
assert.notProperty(raw, "updatedAt");
|
|
89
|
+
assert.property(raw, "created");
|
|
90
|
+
assert.property(raw, "modified");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// The retention sweep deletes inactive events by `modified`, and the cron upserts through
|
|
94
|
+
// findOneAndUpdate, which skips the schema default. Only the timestamps option keeps the
|
|
95
|
+
// field current.
|
|
96
|
+
it("advances modified on findOneAndUpdate", async function() {
|
|
97
|
+
const staleDate = new Date("2020-01-02T03:04:05.000Z");
|
|
98
|
+
await new models.WatchDutyEvent({
|
|
99
|
+
watchDutyId: 222,
|
|
100
|
+
watchDutyCreatedAt: new Date(),
|
|
101
|
+
watchDutyModifiedAt: new Date(),
|
|
102
|
+
}).save();
|
|
103
|
+
await models.WatchDutyEvent.collection.updateOne({
|
|
104
|
+
watchDutyId: 222,
|
|
105
|
+
}, {
|
|
106
|
+
$set: {
|
|
107
|
+
modified: staleDate,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const updated = await models.WatchDutyEvent.findOneAndUpdate({
|
|
112
|
+
watchDutyId: 222,
|
|
113
|
+
}, {
|
|
114
|
+
$set: {
|
|
115
|
+
active: false,
|
|
116
|
+
},
|
|
117
|
+
}, {
|
|
118
|
+
new: true,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
assert.isNotNull(updated);
|
|
122
|
+
assert.isFalse(updated?.active);
|
|
123
|
+
assert.isAbove(Number(updated?.modified), Number(staleDate));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("enforces a unique watchDutyId index", async function() {
|
|
127
|
+
await new models.WatchDutyEvent({
|
|
128
|
+
watchDutyId: 111,
|
|
129
|
+
watchDutyCreatedAt: new Date(),
|
|
130
|
+
watchDutyModifiedAt: new Date(),
|
|
131
|
+
}).save();
|
|
132
|
+
|
|
133
|
+
let thrownError: unknown = null;
|
|
134
|
+
try {
|
|
135
|
+
await new models.WatchDutyEvent({
|
|
136
|
+
watchDutyId: 111,
|
|
137
|
+
watchDutyCreatedAt: new Date(),
|
|
138
|
+
watchDutyModifiedAt: new Date(),
|
|
139
|
+
}).save();
|
|
140
|
+
} catch (e) {
|
|
141
|
+
thrownError = e;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
assert.isNotNull(thrownError, "expected duplicate watchDutyId to be rejected");
|
|
145
|
+
assert.equal((thrownError as { code?: number }).code, 11000);
|
|
146
|
+
assert.include(String((thrownError as Error).message), "E11000");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("requires watchDutyId", async function() {
|
|
150
|
+
let thrownError: unknown = null;
|
|
151
|
+
try {
|
|
152
|
+
await new models.WatchDutyEvent({
|
|
153
|
+
watchDutyCreatedAt: new Date(),
|
|
154
|
+
watchDutyModifiedAt: new Date(),
|
|
155
|
+
}).save();
|
|
156
|
+
} catch (e) {
|
|
157
|
+
thrownError = e;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
assert.isNotNull(thrownError, "expected missing watchDutyId to be rejected");
|
|
161
|
+
assert.include(String((thrownError as Error).message), "watchDutyId");
|
|
162
|
+
});
|
|
163
|
+
});
|
package/src/types/department.ts
CHANGED
|
@@ -546,6 +546,11 @@ export type AccountConfigurationZonehaven = {
|
|
|
546
546
|
fadeZoomLevel: number,
|
|
547
547
|
};
|
|
548
548
|
|
|
549
|
+
export type AccountConfigurationWatchDuty = {
|
|
550
|
+
enabled: boolean,
|
|
551
|
+
visible: boolean,
|
|
552
|
+
};
|
|
553
|
+
|
|
549
554
|
export type ManagedIncidentPriorityItem = {
|
|
550
555
|
title: string,
|
|
551
556
|
color: ColorSchemaType,
|
|
@@ -705,4 +710,5 @@ export interface DepartmentType {
|
|
|
705
710
|
webhook: WebhookConfigType,
|
|
706
711
|
wsFeed: WSFeedConfigType,
|
|
707
712
|
zonehaven: AccountConfigurationZonehaven,
|
|
713
|
+
watchDuty: AccountConfigurationWatchDuty,
|
|
708
714
|
}
|
|
@@ -12,10 +12,18 @@ export type ZonehavenTokenType = {
|
|
|
12
12
|
referer: string | null,
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
// Incremental pull cursor for the Watch Duty events cron. One Watch Duty account feeds every
|
|
16
|
+
// department, so the cursor is global. The cron holds it back when a fetch is incomplete, which
|
|
17
|
+
// is why it is stored and not derived from the events themselves.
|
|
18
|
+
export type WatchDutySyncType = {
|
|
19
|
+
lastModifiedAt: Date | null,
|
|
20
|
+
};
|
|
21
|
+
|
|
15
22
|
export interface GlobalSettingsType {
|
|
16
23
|
_id: Types.ObjectId,
|
|
17
24
|
name: "global",
|
|
18
25
|
arcgisApiKey: ArcGISKeyType,
|
|
19
26
|
zonehavenToken: ZonehavenTokenType,
|
|
27
|
+
watchDutySync: WatchDutySyncType,
|
|
20
28
|
updatedAt: Date,
|
|
21
29
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Types } from "mongoose";
|
|
2
|
+
import { GeoPoint } from "./geojson";
|
|
3
|
+
|
|
4
|
+
export interface WatchDutyRegionType {
|
|
5
|
+
name: string,
|
|
6
|
+
state: string,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface WatchDutyEventType {
|
|
10
|
+
_id: Types.ObjectId,
|
|
11
|
+
watchDutyId: number,
|
|
12
|
+
name: string,
|
|
13
|
+
description: string,
|
|
14
|
+
geoEventType: string,
|
|
15
|
+
// Null when Watch Duty reports no usable lat/lng. The event is still stored, it just cannot
|
|
16
|
+
// be drawn.
|
|
17
|
+
locationGeoJSON: GeoPoint | null,
|
|
18
|
+
address: string,
|
|
19
|
+
isPrescribed: boolean,
|
|
20
|
+
// Watch Duty reports the burned area in acres. It is converted on the way in.
|
|
21
|
+
areaSquareMeters: number | null,
|
|
22
|
+
// Percent of the fire perimeter contained, 0 to 100.
|
|
23
|
+
containment: number | null,
|
|
24
|
+
evacuationOrders: string,
|
|
25
|
+
evacuationWarnings: string,
|
|
26
|
+
evacuationAdvisories: string,
|
|
27
|
+
evacuationShelterInPlace: string,
|
|
28
|
+
regions: WatchDutyRegionType[],
|
|
29
|
+
active: boolean,
|
|
30
|
+
// Watch Duty's own timestamps. `created` and `modified` are ours, and mean the first and the
|
|
31
|
+
// last time we wrote the record.
|
|
32
|
+
watchDutyCreatedAt: Date,
|
|
33
|
+
watchDutyModifiedAt: Date,
|
|
34
|
+
created: Date,
|
|
35
|
+
modified: Date,
|
|
36
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2016 Marius Ursache
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|