tabletcommand-backend-models 5.37.4 → 5.37.6

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.
Files changed (40) hide show
  1. package/build/models/cad-incident-block.js +2 -2
  2. package/build/models/cad-incident-block.js.map +1 -1
  3. package/build/models/managed-incident.js +25 -77
  4. package/build/models/managed-incident.js.map +1 -1
  5. package/build/models/personnel-known.js +4 -0
  6. package/build/models/personnel-known.js.map +1 -1
  7. package/build/models/personnel-roster.js +4 -0
  8. package/build/models/personnel-roster.js.map +1 -1
  9. package/build/models/schema/cad-incident.js +16 -129
  10. package/build/models/schema/cad-incident.js.map +1 -1
  11. package/build/models/schema/shared-incident.js +201 -0
  12. package/build/models/schema/shared-incident.js.map +1 -0
  13. package/definitions/models/cad-incident.d.ts +7 -0
  14. package/definitions/models/cad-incident.d.ts.map +1 -1
  15. package/definitions/models/managed-incident.d.ts +91 -21
  16. package/definitions/models/managed-incident.d.ts.map +1 -1
  17. package/definitions/models/personnel-known.d.ts +6 -1
  18. package/definitions/models/personnel-known.d.ts.map +1 -1
  19. package/definitions/models/personnel-roster.d.ts +5 -0
  20. package/definitions/models/personnel-roster.d.ts.map +1 -1
  21. package/definitions/models/schema/cad-incident.d.ts +7 -0
  22. package/definitions/models/schema/cad-incident.d.ts.map +1 -1
  23. package/definitions/models/schema/shared-incident.d.ts +162 -0
  24. package/definitions/models/schema/shared-incident.d.ts.map +1 -0
  25. package/package.json +1 -1
  26. package/src/models/cad-incident-block.ts +2 -2
  27. package/src/models/managed-incident.ts +35 -83
  28. package/src/models/personnel-known.ts +5 -1
  29. package/src/models/personnel-roster.ts +4 -1
  30. package/src/models/schema/cad-incident.ts +25 -137
  31. package/src/models/schema/shared-incident.ts +217 -0
  32. package/test/cad-incident-block.js +44 -0
  33. package/test/cad-incident.js +57 -0
  34. package/test/managed-incident.js +57 -0
  35. package/test/mock.js +245 -85
  36. package/build/models/schema/report-number.js +0 -25
  37. package/build/models/schema/report-number.js.map +0 -1
  38. package/definitions/models/schema/report-number.d.ts +0 -16
  39. package/definitions/models/schema/report-number.d.ts.map +0 -1
  40. package/src/models/schema/report-number.ts +0 -27
@@ -11,13 +11,16 @@ import {
11
11
  import * as uuid from "uuid";
12
12
  import * as mongooseLeanVirtuals from "mongoose-lean-virtuals";
13
13
  import { IncidentEventSchema } from "../incident-event";
14
- import ReportNumberModule from "./report-number";
14
+ import {
15
+ CADPersonSchema,
16
+ RadioChannelSchema,
17
+ RecordSchema,
18
+ ReportNumberSchema,
19
+ SharedSourceSchema,
20
+ SharedToSchema,
21
+ } from "./shared-incident";
15
22
 
16
23
  export function CADIncidentSchema(mongoose: MongooseModule) {
17
- const { Schema, Types } = mongoose;
18
- const IncidentEvent = IncidentEventSchema(mongoose);
19
- const ReportNumber = ReportNumberModule(mongoose);
20
-
21
24
  const toJSONOpts = {
22
25
  versionKey: false,
23
26
  transform(doc: DocumentTypeFromSchema<typeof modelSchema>, ret: FieldsOfDocument<DocumentTypeFromSchema<typeof modelSchema>>) {
@@ -25,6 +28,23 @@ export function CADIncidentSchema(mongoose: MongooseModule) {
25
28
  },
26
29
  };
27
30
 
31
+ const { Schema, Types } = mongoose;
32
+ const IncidentEvent = IncidentEventSchema(mongoose);
33
+
34
+ // Share incident properties - copy to managed incidents
35
+ const CADPerson = CADPersonSchema(mongoose);
36
+ CADPerson.set("toJSON", toJSONOpts);
37
+ const RadioChannel = RadioChannelSchema(mongoose);
38
+ RadioChannel.set("toJSON", toJSONOpts);
39
+ const RecordValue = RecordSchema(mongoose);
40
+ RecordValue.set("toJSON", toJSONOpts);
41
+ const ReportNumber = ReportNumberSchema(mongoose);
42
+ ReportNumber.set("toJSON", toJSONOpts);
43
+ const SharedSource = SharedSourceSchema(mongoose);
44
+ SharedSource.set("toJSON", toJSONOpts);
45
+ const SharedTo = SharedToSchema(mongoose);
46
+ SharedTo.set("toJSON", toJSONOpts);
47
+
28
48
  // Currently, supporting type: "ack", item: "knife"
29
49
  const CADCommentOpts = createSchema(Schema, {
30
50
  type: {
@@ -62,28 +82,6 @@ export function CADIncidentSchema(mongoose: MongooseModule) {
62
82
  });
63
83
  CADComment.set("toJSON", toJSONOpts);
64
84
 
65
- const CADPerson = createSchema(Schema, {
66
- PersonnelID: {
67
- type: String,
68
- },
69
- PersonnelName: {
70
- type: String,
71
- },
72
- PersonnelRank: {
73
- type: String,
74
- },
75
- PersonnelWorkCode: {
76
- type: String,
77
- },
78
- PersonnelNote: {
79
- type: String,
80
- },
81
- }, {
82
- _id: false,
83
- id: false,
84
- });
85
- CADPerson.set("toJSON", toJSONOpts);
86
-
87
85
  const CADUnit = createSchema(Schema, {
88
86
  UnitID: {
89
87
  type: String,
@@ -182,116 +180,6 @@ export function CADIncidentSchema(mongoose: MongooseModule) {
182
180
  });
183
181
  CADPriorIncident.set("toJSON", toJSONOpts);
184
182
 
185
- const RadioChannel = createSchema(Schema, {
186
- name: {
187
- type: String,
188
- default: "",
189
- },
190
- channel: {
191
- type: String,
192
- default: "",
193
- },
194
- url: {
195
- type: String,
196
- default: "",
197
- },
198
- }, {
199
- _id: false,
200
- id: false,
201
- });
202
- RadioChannel.set("toJSON", toJSONOpts);
203
-
204
- const RecordValue = createSchema(Schema, {
205
- name: {
206
- type: String,
207
- default: "",
208
- },
209
- value: {
210
- type: String,
211
- default: "",
212
- },
213
- }, {
214
- _id: false,
215
- id: false,
216
- });
217
- RecordValue.set("toJSON", toJSONOpts);
218
-
219
- const ShareReason = createSchema(Schema, {
220
- name: {
221
- type: String,
222
- default: "",
223
- },
224
- date: {
225
- type: Date,
226
- default: currentDate,
227
- },
228
- }, {
229
- _id: false,
230
- id: false,
231
- });
232
- ShareReason.set("toJSON", toJSONOpts);
233
-
234
- const SharedTo = createSchema(Schema, {
235
- departmentId: {
236
- type: String,
237
- default: "",
238
- },
239
- // Department Name
240
- name: {
241
- type: String,
242
- default: "",
243
- },
244
- startAt: {
245
- type: Date,
246
- default: currentDate,
247
- },
248
- expireAt: {
249
- type: Date,
250
- default: currentDate,
251
- },
252
- active: {
253
- type: Boolean,
254
- default: true, // overwritten later, when expireAt is older than now
255
- },
256
- reasons: {
257
- type: [ShareReason],
258
- default: [],
259
- }
260
- }, {
261
- _id: false,
262
- id: false,
263
- });
264
- SharedTo.set("toJSON", toJSONOpts);
265
-
266
- const SharedSource = createSchema(Schema, {
267
- // Department Name (always matches record .departmentId)
268
- name: {
269
- type: String,
270
- default: "",
271
- },
272
- // Output overwritten by backend when record is included in another department's list
273
- isExternal: {
274
- type: Boolean,
275
- default: false,
276
- },
277
-
278
- // Output will be overwritten by backend
279
- startAt: {
280
- type: Date,
281
- },
282
- expireAt: {
283
- type: Date,
284
- },
285
- reasons: {
286
- type: [ShareReason],
287
- default: [],
288
- }
289
- }, {
290
- _id: false,
291
- id: false,
292
- });
293
- SharedSource.set("toJSON", toJSONOpts);
294
-
295
183
  // Main schema
296
184
  const modelSchema = createSchema(Schema, {
297
185
  _id: {
@@ -0,0 +1,217 @@
1
+ import {
2
+ MongooseModule,
3
+ createSchema,
4
+ currentDate,
5
+ } from "../../helpers";
6
+
7
+ // Properties shared between CAD and Managed Incident
8
+ // They are copied on iOS
9
+
10
+ export function CADPersonSchema(mongoose: MongooseModule) {
11
+ const { Schema } = mongoose;
12
+
13
+ const Person = createSchema(Schema, {
14
+ PersonnelID: {
15
+ type: String,
16
+ },
17
+ PersonnelName: {
18
+ type: String,
19
+ },
20
+ PersonnelRank: {
21
+ type: String,
22
+ default: ""
23
+ },
24
+ PersonnelWorkCode: {
25
+ type: String,
26
+ default: ""
27
+ },
28
+ PersonnelNote: {
29
+ type: String,
30
+ default: ""
31
+ },
32
+ }, {
33
+ _id: false,
34
+ id: false,
35
+ });
36
+
37
+ return Person;
38
+ }
39
+
40
+ export function RadioChannelSchema(mongoose: MongooseModule) {
41
+ const { Schema } = mongoose;
42
+
43
+ const RadioChannel = createSchema(Schema, {
44
+ name: {
45
+ type: String,
46
+ default: "",
47
+ },
48
+ channel: {
49
+ type: String,
50
+ default: "",
51
+ },
52
+ url: {
53
+ type: String,
54
+ default: "",
55
+ },
56
+ channelDescription: {
57
+ type: String,
58
+ default: "",
59
+ },
60
+ }, {
61
+ _id: false,
62
+ id: false,
63
+ toJSON: {
64
+ versionKey: false,
65
+ }
66
+ });
67
+
68
+ return RadioChannel;
69
+ }
70
+
71
+ export function RecordSchema(mongoose: MongooseModule) {
72
+ const { Schema } = mongoose;
73
+
74
+ const Record = createSchema(Schema, {
75
+ name: {
76
+ type: String,
77
+ default: ""
78
+ },
79
+ value: {
80
+ type: String,
81
+ default: "",
82
+ },
83
+ }, {
84
+ _id: false,
85
+ id: false,
86
+ toJSON: {
87
+ versionKey: false,
88
+ }
89
+ });
90
+
91
+ return Record;
92
+ }
93
+
94
+ export function ReportNumberSchema(mongoose: MongooseModule) {
95
+ const { Schema } = mongoose;
96
+
97
+ const ReportNumber = createSchema(Schema, {
98
+ name: {
99
+ type: String,
100
+ default: "",
101
+ },
102
+ number: {
103
+ type: String,
104
+ default: "",
105
+ },
106
+ }, {
107
+ _id: false,
108
+ id: false,
109
+ toJSON: {
110
+ versionKey: false,
111
+ }
112
+ });
113
+
114
+ return ReportNumber;
115
+ }
116
+
117
+ export function ShareReasonSchema(mongoose: MongooseModule) {
118
+ const { Schema } = mongoose;
119
+
120
+ const ShareReason = createSchema(Schema, {
121
+ name: {
122
+ type: String,
123
+ default: "",
124
+ },
125
+ date: {
126
+ type: Date,
127
+ default: currentDate,
128
+ },
129
+ }, {
130
+ _id: false,
131
+ id: false,
132
+ toJSON: {
133
+ versionKey: false,
134
+ },
135
+ });
136
+
137
+ return ShareReason;
138
+ }
139
+
140
+ export function SharedToSchema(mongoose: MongooseModule) {
141
+ const { Schema } = mongoose;
142
+ const ShareReason = ShareReasonSchema(mongoose);
143
+
144
+ const SharedTo = createSchema(Schema, {
145
+ departmentId: {
146
+ type: String,
147
+ default: "",
148
+ },
149
+ // Department Name
150
+ name: {
151
+ type: String,
152
+ default: "",
153
+ },
154
+ startAt: {
155
+ type: Date,
156
+ default: currentDate,
157
+ },
158
+ expireAt: {
159
+ type: Date,
160
+ default: currentDate,
161
+ },
162
+ active: {
163
+ type: Boolean,
164
+ default: true, // overwritten later, when expireAt is older than now
165
+ },
166
+ reasons: {
167
+ type: [ShareReason],
168
+ default: [],
169
+ }
170
+ }, {
171
+ _id: false,
172
+ id: false,
173
+ toJSON: {
174
+ versionKey: false,
175
+ }
176
+ });
177
+
178
+ return SharedTo;
179
+ }
180
+
181
+ export function SharedSourceSchema(mongoose: MongooseModule) {
182
+ const { Schema } = mongoose;
183
+ const ShareReason = ShareReasonSchema(mongoose);
184
+
185
+ const SharedSource = createSchema(Schema, {
186
+ // Department Name (always matches record .departmentId)
187
+ name: {
188
+ type: String,
189
+ default: "",
190
+ },
191
+ // Output overwritten by backend when record is included in another department's list
192
+ isExternal: {
193
+ type: Boolean,
194
+ default: false,
195
+ },
196
+
197
+ // Output will be overwritten by backend
198
+ startAt: {
199
+ type: Date,
200
+ },
201
+ expireAt: {
202
+ type: Date,
203
+ },
204
+ reasons: {
205
+ type: [ShareReason],
206
+ default: [],
207
+ }
208
+ }, {
209
+ _id: false,
210
+ id: false,
211
+ toJSON: {
212
+ versionKey: false,
213
+ }
214
+ });
215
+
216
+ return SharedSource;
217
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ const _ = require("lodash");
4
+ const assert = require("chai").assert;
5
+
6
+ const m = require("..");
7
+ const config = require("./config");
8
+
9
+ describe("CADIncidentBlock", function() {
10
+ let models, mongoose;
11
+ let testItem;
12
+ beforeEach(async function() {
13
+ const c = await m.connect(config.url);
14
+ models = c.models;
15
+ mongoose = c.mongoose;
16
+
17
+ const mock = require("./mock")({
18
+ mongoose
19
+ });
20
+ testItem = mock.cadIncidentBlock;
21
+ await mock.beforeEach();
22
+ });
23
+ afterEach(function() {
24
+ mongoose.disconnect();
25
+ });
26
+
27
+ it("is saved", async function() {
28
+ const item = new models.CADIncidentBlock(testItem);
29
+ const sut = await item.save();
30
+
31
+ assert.isNotNull(testItem._id);
32
+ assert.equal(sut.EntryDateTime, testItem.EntryDateTime);
33
+ assert.equal(sut.ClosedDateTime, testItem.ClosedDateTime);
34
+ assert.equal(sut.source, testItem.source);
35
+ assert.equal(sut.IncidentNumber, testItem.IncidentNumber);
36
+ assert.equal(sut.departmentId, testItem.departmentId);
37
+ assert.equal(sut.AgencyIncidentCallTypeDescription, testItem.AgencyIncidentCallTypeDescription);
38
+ assert.equal(sut.createdAt.toISOString(), new Date(testItem.createdAt).toISOString());
39
+ assert.equal(sut.ReportNumber.length, 1);
40
+ const rn = _.first(sut.ReportNumber);
41
+ assert.equal(rn.name, "Incident");
42
+ assert.equal(rn.number, "CA68");
43
+ });
44
+ });
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ const _ = require("lodash");
3
4
  const assert = require("chai").assert;
4
5
 
5
6
  const m = require("..");
@@ -81,11 +82,67 @@ describe("CADIncident", function() {
81
82
  assert.equal(sut.units[0].UnitDispatchNumber, testItem.units[0].UnitDispatchNumber);
82
83
  assert.equal(sut.units[0].UnitID, testItem.units[0].UnitID);
83
84
  assert.equal(sut.units[0].TimeDispatched, testItem.units[0].TimeDispatched);
85
+
86
+ const unit = _.first(sut.units.filter((x) => x.UnitID === "MA31"));
87
+ assert.equal(unit.Personnel.length, 2);
88
+ const p1 = _.first(unit.Personnel.filter((x) => x.PersonnelID === "X14"));
89
+ assert.equal(p1.PersonnelName, "Mary Smith");
90
+ assert.equal(p1.PersonnelNote, "X");
91
+ assert.equal(p1.PersonnelRank, "Captain");
92
+ assert.equal(p1.PersonnelWorkCode, "TRD");
84
93
 
85
94
  assert.equal(sut.Comment.length, 1);
86
95
  assert.equal(sut.Comment[0].Comment, testItem.Comment[0].Comment);
87
96
  assert.equal(sut.Comment[0].CommentSource, testItem.Comment[0].CommentSource);
88
97
  assert.equal(sut.Comment[0].CommentDateTime, testItem.Comment[0].CommentDateTime);
98
+
99
+ // Share incident properties
100
+ assert.isArray(sut.ReportNumber);
101
+ assert.equal(sut.ReportNumber.length, 2);
102
+ const rna = _.first(sut.ReportNumber.filter((x) => x.name === "A"));
103
+ assert.isObject(rna);
104
+ assert.equal(rna.number, "07-0351");
105
+ const rnb = _.first(sut.ReportNumber.filter((x) => x.name === "B"));
106
+ assert.isObject(rnb);
107
+ assert.equal(rnb.number, "UM-02210");
108
+
109
+ assert.isArray(sut.radioChannels);
110
+ assert.equal(sut.radioChannels.length, 2);
111
+ const rca = _.first(sut.radioChannels.filter((x) => x.name === "CMD"));
112
+ assert.isObject(rca);
113
+ assert.equal(rca.channel, "LOCAL Tone: 3");
114
+ assert.equal(rca.url, "http://example.com/stream1");
115
+ const rcb = _.first(sut.radioChannels.filter((x) => x.name === "TAC"));
116
+ assert.isObject(rcb);
117
+ assert.equal(rcb.channel, "CDF TAC 10");
118
+ assert.equal(rcb.url, "http://example.com/stream2");
119
+
120
+ assert.isObject(sut.record);
121
+ assert.equal(sut.record.name, "John");
122
+ assert.equal(sut.record.value, "Smith");
123
+
124
+ assert.isObject(sut.sharedSource);
125
+ assert.equal(sut.sharedSource.isExternal, true);
126
+ assert.equal(sut.sharedSource.name, "Demo RTS Fire Department");
127
+ assert.isArray(sut.sharedSource.reasons);
128
+ assert.equal(sut.sharedSource.reasons.length, 1);
129
+ const ssr1 = _.first(sut.sharedSource.reasons);
130
+ assert.isObject(ssr1);
131
+ assert.equal(ssr1.name, "Unit B10 assigned");
132
+ assert.equal(ssr1.date.toISOString(), "2024-05-03T00:00:00.000Z");
133
+
134
+ assert.isArray(sut.sharedTo);
135
+ assert.equal(sut.sharedTo.length, 1);
136
+ const st1 = _.first(sut.sharedTo);
137
+ assert.equal(st1.active, true);
138
+ assert.equal(st1.departmentId, "5195426cc4e016a988000965");
139
+ assert.equal(st1.expireAt.toISOString(), "2024-08-01T10:20:30.400Z");
140
+ assert.equal(st1.name, "Test Fire Department");
141
+ assert.equal(st1.startAt.toISOString(), "2024-05-01T01:02:03.040Z");
142
+ assert.equal(st1.reasons.length, 1);
143
+ const str1 = _.first(st1.reasons);
144
+ assert.equal(str1.name, "Unit M10 assigned");
145
+ assert.equal(str1.date.toISOString(), "2024-05-03T01:01:01.010Z");
89
146
  });
90
147
 
91
148
  it("no virtuals id if _id not present", async function() {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ const _ = require("lodash");
3
4
  const assert = require("chai").assert;
4
5
 
5
6
  const m = require("..");
@@ -57,6 +58,62 @@ describe("ManagedIncident", function() {
57
58
  assert.isTrue(sut.active);
58
59
  assert.isTrue(sut.is_closed);
59
60
 
61
+ const unit = _.first(sut.units.filter((x) => x.UnitID === "M12"));
62
+ assert.equal(unit.Personnel.length, 2);
63
+ const p1 = _.first(unit.Personnel.filter((x) => x.PersonnelID === "X14"));
64
+ assert.equal(p1.PersonnelName, "Mary Smith");
65
+ assert.equal(p1.PersonnelNote, "X");
66
+ assert.equal(p1.PersonnelRank, "Captain");
67
+ assert.equal(p1.PersonnelWorkCode, "TRD");
68
+
69
+ // Share incident properties
70
+ assert.isArray(sut.ReportNumber);
71
+ assert.equal(sut.ReportNumber.length, 2);
72
+ const rna = _.first(sut.ReportNumber.filter((x) => x.name === "A"));
73
+ assert.isObject(rna);
74
+ assert.equal(rna.number, "07-0351");
75
+ const rnb = _.first(sut.ReportNumber.filter((x) => x.name === "B"));
76
+ assert.isObject(rnb);
77
+ assert.equal(rnb.number, "UM-02210");
78
+
79
+ assert.isArray(sut.radioChannels);
80
+ assert.equal(sut.radioChannels.length, 2);
81
+ const rca = _.first(sut.radioChannels.filter((x) => x.name === "CMD"));
82
+ assert.isObject(rca);
83
+ assert.equal(rca.channel, "LOCAL Tone: 3");
84
+ assert.equal(rca.url, "http://example.com/stream1");
85
+ const rcb = _.first(sut.radioChannels.filter((x) => x.name === "TAC"));
86
+ assert.isObject(rcb);
87
+ assert.equal(rcb.channel, "CDF TAC 10");
88
+ assert.equal(rcb.url, "http://example.com/stream2");
89
+
90
+ assert.isObject(sut.record);
91
+ assert.equal(sut.record.name, "John");
92
+ assert.equal(sut.record.value, "Smith");
93
+
94
+ assert.isObject(sut.sharedSource);
95
+ assert.equal(sut.sharedSource.isExternal, true);
96
+ assert.equal(sut.sharedSource.name, "Demo RTS Fire Department");
97
+ assert.isArray(sut.sharedSource.reasons);
98
+ assert.equal(sut.sharedSource.reasons.length, 1);
99
+ const ssr1 = _.first(sut.sharedSource.reasons);
100
+ assert.isObject(ssr1);
101
+ assert.equal(ssr1.name, "Unit B10 assigned");
102
+ assert.equal(ssr1.date.toISOString(), "2024-05-03T00:00:00.000Z");
103
+
104
+ assert.isArray(sut.sharedTo);
105
+ assert.equal(sut.sharedTo.length, 1);
106
+ const st1 = _.first(sut.sharedTo);
107
+ assert.equal(st1.active, true);
108
+ assert.equal(st1.departmentId, "5195426cc4e016a988000965");
109
+ assert.equal(st1.expireAt.toISOString(), "2024-08-01T10:20:30.400Z");
110
+ assert.equal(st1.name, "Test Fire Department");
111
+ assert.equal(st1.startAt.toISOString(), "2024-05-01T01:02:03.040Z");
112
+ assert.equal(st1.reasons.length, 1);
113
+ const str1 = _.first(st1.reasons);
114
+ assert.equal(str1.name, "Unit M10 assigned");
115
+ assert.equal(str1.date.toISOString(), "2024-05-03T01:01:01.010Z");
116
+
60
117
  return done();
61
118
  });
62
119
  });