tabletcommand-backend-models 5.27.1 → 5.28.1

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.
@@ -0,0 +1,507 @@
1
+ import {
2
+ createSchema,
3
+ currentDate,
4
+ DocumentTypeFromSchema,
5
+ FieldsOfDocument,
6
+ ModelFromSchema,
7
+ MongooseDocument,
8
+ MongooseModule,
9
+ } from "../../helpers";
10
+
11
+ import * as uuid from "uuid";
12
+ import * as mongooseLeanVirtuals from "mongoose-lean-virtuals";
13
+ import { IncidentEventSchema } from "../incident-event";
14
+
15
+ export function CADIncidentSchema(mongoose: MongooseModule) {
16
+ const { Schema, Types } = mongoose;
17
+ const IncidentEvent = IncidentEventSchema(mongoose);
18
+
19
+ const toJSONOpts = {
20
+ versionKey: false,
21
+ transform(doc: DocumentTypeFromSchema<typeof modelSchema>, ret: FieldsOfDocument<DocumentTypeFromSchema<typeof modelSchema>>) {
22
+ strictSchema(doc.schema, ret);
23
+ },
24
+ };
25
+
26
+ const CADComment = createSchema(Schema, {
27
+ Comment: {
28
+ type: String,
29
+ },
30
+ CommentSource: {
31
+ type: String,
32
+ },
33
+ CommentDateTime: {
34
+ type: String,
35
+ },
36
+ CommentConfidential: {
37
+ type: Boolean,
38
+ default: false
39
+ }
40
+ }, {
41
+ _id: false,
42
+ id: false,
43
+ });
44
+ CADComment.set("toJSON", toJSONOpts);
45
+
46
+ const CADPerson = createSchema(Schema, {
47
+ PersonnelID: {
48
+ type: String,
49
+ },
50
+ PersonnelName: {
51
+ type: String,
52
+ },
53
+ PersonnelRank: {
54
+ type: String,
55
+ },
56
+ PersonnelWorkCode: {
57
+ type: String,
58
+ },
59
+ PersonnelNote: {
60
+ type: String,
61
+ },
62
+ }, {
63
+ _id: false,
64
+ id: false,
65
+ });
66
+ CADPerson.set("toJSON", toJSONOpts);
67
+
68
+ const CADUnit = createSchema(Schema, {
69
+ UnitID: {
70
+ type: String,
71
+ required: true,
72
+ },
73
+ UnitDispatchNumber: {
74
+ type: String,
75
+ required: true,
76
+ },
77
+ AlarmAtDispatch: {
78
+ type: String,
79
+ },
80
+ TimeDispatched: {
81
+ type: String,
82
+ },
83
+ TimeEnroute: {
84
+ type: String,
85
+ },
86
+ TimeArrived: {
87
+ type: String,
88
+ },
89
+ TimeStaged: {
90
+ type: String,
91
+ },
92
+ TimeCleared: {
93
+ type: String,
94
+ },
95
+ TimeAtHospital: {
96
+ type: String,
97
+ },
98
+ TimePatient: {
99
+ type: String,
100
+ },
101
+ TimeTransport: {
102
+ type: String,
103
+ },
104
+ TimeTransporting: {
105
+ type: String,
106
+ },
107
+
108
+ PersonnelCount: {
109
+ type: Number,
110
+ },
111
+ Personnel: [CADPerson],
112
+ }, {
113
+ _id: false,
114
+ id: false,
115
+ });
116
+ CADUnit.set("toJSON", toJSONOpts);
117
+
118
+ const APNNotificationType = createSchema(Schema, {
119
+ name: {
120
+ type: String,
121
+ },
122
+ value: {
123
+ type: String,
124
+ },
125
+ }, {
126
+ _id: false,
127
+ id: false,
128
+ });
129
+ APNNotificationType.set("toJSON", toJSONOpts);
130
+
131
+ const CADPriorIncident = createSchema(Schema, {
132
+ Address: {
133
+ type: String,
134
+ },
135
+ Comment: {
136
+ type: [CADComment],
137
+ },
138
+ IncidentDateTime: {
139
+ type: String,
140
+ },
141
+ IncidentNumber: {
142
+ type: String,
143
+ },
144
+ Jurisdiction: {
145
+ type: String,
146
+ },
147
+ Problem: {
148
+ type: String,
149
+ },
150
+ Suite: {
151
+ type: String,
152
+ },
153
+ }, {
154
+ _id: false,
155
+ id: false,
156
+ });
157
+ CADPriorIncident.set("toJSON", toJSONOpts);
158
+
159
+ const RadioChannel = createSchema(Schema, {
160
+ name: {
161
+ type: String,
162
+ default: "",
163
+ },
164
+ channel: {
165
+ type: String,
166
+ default: "",
167
+ },
168
+ }, {
169
+ _id: false,
170
+ id: false,
171
+ });
172
+ RadioChannel.set("toJSON", toJSONOpts);
173
+
174
+ const ReportNumber = createSchema(Schema, {
175
+ name: {
176
+ type: String,
177
+ default: "",
178
+ },
179
+ number: {
180
+ type: String,
181
+ default: "",
182
+ },
183
+ }, {
184
+ _id: false,
185
+ id: false,
186
+ });
187
+ ReportNumber.set("toJSON", toJSONOpts);
188
+
189
+ const modelSchema = createSchema(Schema, {
190
+ _id: {
191
+ type: Types.ObjectId,
192
+ auto: true,
193
+ },
194
+ uuid: {
195
+ type: String,
196
+ default: uuid.v4,
197
+ },
198
+ departmentId: {
199
+ type: String,
200
+ default: "",
201
+ required: true,
202
+ index: true,
203
+ },
204
+ AgencyID: {
205
+ type: String,
206
+ default: "",
207
+ },
208
+ IncidentNumber: {
209
+ type: String,
210
+ required: true,
211
+ },
212
+ TransactionID: {
213
+ type: String,
214
+ default: "",
215
+ },
216
+
217
+ // Incident Specific
218
+ AgencyIncidentCallTypeDescription: {
219
+ type: String,
220
+ },
221
+ AgencyIncidentCallType: {
222
+ type: String,
223
+ },
224
+ AgencyIncidentCallSubTypeDescription: {
225
+ type: String,
226
+ },
227
+ AgencyIncidentCallSubType: {
228
+ type: String,
229
+ },
230
+ AgencyIncidentPriorityDescription: {
231
+ type: String,
232
+ },
233
+ PulsePointIncidentCallType: {
234
+ type: String,
235
+ },
236
+ PulsePointDeterminantCode: {
237
+ type: String,
238
+ },
239
+ AlarmLevel: {
240
+ type: String,
241
+ },
242
+ CommandName: {
243
+ type: String,
244
+ },
245
+ FireMap: {
246
+ type: String,
247
+ },
248
+ TBMap: {
249
+ type: String,
250
+ },
251
+ MapPages: {
252
+ type: String,
253
+ },
254
+ TacticalChannel: {
255
+ type: String,
256
+ },
257
+ TacticalAltChannel: {
258
+ type: String,
259
+ },
260
+ CommandChannel: {
261
+ type: String,
262
+ },
263
+
264
+ // Dates
265
+ EntryDateTime: {
266
+ type: String,
267
+ },
268
+ ClosedDateTime: {
269
+ type: String,
270
+ },
271
+ CallReceivedDateTime: {
272
+ type: String,
273
+ },
274
+ DispatchDateTime: {
275
+ type: String,
276
+ },
277
+ IncidentLastUpdate: {
278
+ type: String,
279
+ },
280
+ EnrouteDateTime: {
281
+ type: String,
282
+ },
283
+ OnSceneDateTime: {
284
+ type: String,
285
+ },
286
+
287
+ modified_date: {
288
+ type: String,
289
+ },
290
+ modified_unix_date: {
291
+ type: Number,
292
+ },
293
+ modified: {
294
+ type: Date,
295
+ default: currentDate,
296
+ },
297
+ start_unix_date: {
298
+ type: Number,
299
+ },
300
+ closed_unix_date: {
301
+ type: Number,
302
+ },
303
+ queued_at: {
304
+ type: Number,
305
+ },
306
+ scheduled_at: {
307
+ type: Number,
308
+ },
309
+ ignored: {
310
+ type: Boolean,
311
+ default: false,
312
+ },
313
+ expiration_date: {
314
+ type: Date,
315
+ default: null,
316
+ },
317
+
318
+ // Address fields
319
+ StreetName: {
320
+ type: String,
321
+ },
322
+ StreetSuffix: {
323
+ type: String,
324
+ },
325
+ Predirectional: {
326
+ type: String,
327
+ },
328
+ Postdirectional: {
329
+ type: String,
330
+ },
331
+ CityOrLocality: {
332
+ type: String,
333
+ },
334
+ StateOrProvince: {
335
+ type: String,
336
+ },
337
+ // Legacy
338
+ StateOfProvince: {
339
+ type: String,
340
+ },
341
+ CommonPlaceName: {
342
+ type: String,
343
+ },
344
+ CrossStreet1: {
345
+ type: String,
346
+ },
347
+ CrossStreet2: {
348
+ type: String,
349
+ },
350
+ StreetNumber: {
351
+ type: String,
352
+ },
353
+ Building: {
354
+ type: String,
355
+ },
356
+ Floor: {
357
+ type: String,
358
+ },
359
+ Suite: {
360
+ type: String,
361
+ },
362
+ City: {
363
+ type: String,
364
+ },
365
+ County: {
366
+ type: String,
367
+ },
368
+ PostalCode: {
369
+ type: String,
370
+ },
371
+ CrossStreetName: {
372
+ type: String,
373
+ },
374
+ LocationComment: {
375
+ type: String,
376
+ },
377
+ // TC Address
378
+ full_address: {
379
+ type: String,
380
+ },
381
+ address: {
382
+ type: String,
383
+ },
384
+ cross_streets: {
385
+ type: String,
386
+ },
387
+
388
+ // Prior History
389
+ PriorIncidentChanged: {
390
+ type: Boolean,
391
+ },
392
+ PriorIncident: {
393
+ type: [CADPriorIncident],
394
+ default: [],
395
+ },
396
+
397
+ // Caller
398
+ CallerNumber: {
399
+ type: String,
400
+ default: "",
401
+ },
402
+
403
+ ReportNumber: {
404
+ type: [ReportNumber],
405
+ default: [],
406
+ },
407
+
408
+ radioChannels: {
409
+ type: [RadioChannel],
410
+ default: [],
411
+ },
412
+
413
+ // Coordinate
414
+ Latitude: {
415
+ type: Number,
416
+ },
417
+ Longitude: {
418
+ type: Number,
419
+ },
420
+
421
+ Comment: {
422
+ type: [CADComment],
423
+ default: [],
424
+ },
425
+
426
+ units: {
427
+ type: [CADUnit],
428
+ default: [],
429
+ },
430
+
431
+ events: {
432
+ type: [IncidentEvent], // setting types as object, because it does not work with importing IncidentEvent
433
+ default: [],
434
+ },
435
+
436
+ // Tablet Command Internal fields
437
+ preference_location: {
438
+ type: String,
439
+ },
440
+
441
+ // Training
442
+ simulation: {
443
+ type: Boolean,
444
+ default: false,
445
+ },
446
+ notify: {
447
+ type: Boolean,
448
+ default: true,
449
+ },
450
+ rts: {
451
+ type: Boolean,
452
+ default: true,
453
+ },
454
+
455
+ notificationType: {
456
+ type: [APNNotificationType],
457
+ default: [],
458
+ },
459
+
460
+ }, {
461
+ autoIndex: false,
462
+ // Set collection and strict after importing
463
+ // collection: "massive_incident_cad",
464
+ // strict: false, // Because we accept all kind of data in
465
+ });
466
+
467
+ modelSchema.set("toJSON", {
468
+ virtuals: true,
469
+ versionKey: false,
470
+ transform(doc: ModelFromSchema<typeof modelSchema>, ret: DocumentTypeFromSchema<typeof modelSchema>) {
471
+ // Remove fields that should not be here
472
+ delete (ret as unknown as { apikey: unknown }).apikey;
473
+
474
+ strictSchema(doc.schema as typeof modelSchema, ret);
475
+
476
+ ret.id = ret._id;
477
+ },
478
+ });
479
+
480
+ modelSchema.virtual("id").get(function(this: MongooseDocument) {
481
+ // tslint:disable-next-line: no-unsafe-any
482
+ return this._id.toString();
483
+ });
484
+
485
+ const ignoreFields: ReadonlyArray<string> = ["station", "callerNumber"];
486
+
487
+ function strictSchema(schema: typeof modelSchema, ret: Record<string, unknown>) {
488
+ Object.keys(ret).forEach(function(element) {
489
+ // Don't complain about the virtuals
490
+ if (element === "id") {
491
+ return;
492
+ }
493
+
494
+ if (ignoreFields.indexOf(element) !== -1) {
495
+ delete ret[element];
496
+ return;
497
+ }
498
+ const pathSchema = schema as unknown as { paths: Record<string, string> };
499
+ if (pathSchema.paths[element] === undefined) {
500
+ // console.log("backend-models.cad-incident: undefined schema.paths[element]:", element, pathSchema.paths[element]);
501
+ delete ret[element];
502
+ }
503
+ });
504
+ }
505
+ modelSchema.plugin(mongooseLeanVirtuals);
506
+ return modelSchema;
507
+ }
@@ -130,7 +130,7 @@ export function TemplateSchema(mongoose: MongooseModule) {
130
130
  }
131
131
  const pathSchema = schema as unknown as { paths: Record<string, string> };
132
132
  if (pathSchema.paths[element] === undefined) {
133
- // console.log("backend-models.cad-incident: undefined schema.paths[element]:", element, pathSchema.paths[element]);
133
+ // console.log("backend-models.template: undefined schema.paths[element]:", element, pathSchema.paths[element]);
134
134
  delete ret[element];
135
135
  }
136
136
  });
package/test/0index.js CHANGED
@@ -25,6 +25,7 @@ describe(" Models", function() {
25
25
  assert.isFunction(models.Battalion, "Missing Battalion");
26
26
  assert.isFunction(models.BeaconLog, "Missing BeaconLog");
27
27
  assert.isFunction(models.CADIncident, "Missing CADIncident");
28
+ assert.isFunction(models.CADIncidentFlat, "Missing CADIncidentFlat");
28
29
  assert.isFunction(models.CADIncidentStream, "Missing CADIncidentStream");
29
30
  assert.isFunction(models.CADStatus, "Missing CADStatus");
30
31
  assert.isFunction(models.CADStatusMap, "Missing CADStatusMap");
package/test/mock.js CHANGED
@@ -719,8 +719,9 @@ module.exports = function(dependencies) {
719
719
  _id: mongoose.Types.ObjectId(),
720
720
  departmentId: "546ace2b3cd8d60d1d00256a",
721
721
  agencyId: "123",
722
- notificationType: "maps-token-error",
722
+ notificationType: "maps-auth-error",
723
723
  status: "active",
724
+ sentAt: new Date(1000.0 * 1603263604),
724
725
  sentUnixDate: 1603263604
725
726
  };
726
727