tabletcommand-incident 0.4.16 → 0.6.0

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 (109) hide show
  1. package/.cspell/project-words.txt +2 -0
  2. package/build/domain.js +7 -8
  3. package/build/domain.js.map +1 -1
  4. package/build/incidentProcessor.js +15 -12
  5. package/build/incidentProcessor.js.map +1 -1
  6. package/build/ruleProcessorLegacy.js +1 -1
  7. package/build/ruleProcessorLegacy.js.map +1 -1
  8. package/build/rules/clean-up-comments.js.map +1 -1
  9. package/build/rules/clear-field.js +1 -1
  10. package/build/rules/clear-field.js.map +1 -1
  11. package/build/rules/close-incident-after-hours.js.map +1 -1
  12. package/build/rules/close-incident-matching-incident-number.js.map +1 -1
  13. package/build/rules/close-incident-of-certain-type.js.map +1 -1
  14. package/build/rules/copy-incident-number.js.map +1 -1
  15. package/build/rules/copy-location-comment.js.map +1 -1
  16. package/build/rules/index.js +13 -4
  17. package/build/rules/index.js.map +1 -1
  18. package/build/rules/join-call-type-priority.js +18 -14
  19. package/build/rules/join-call-type-priority.js.map +1 -1
  20. package/build/rules/join-call-type-sacramento.js +50 -0
  21. package/build/rules/join-call-type-sacramento.js.map +1 -0
  22. package/build/rules/map-unit-dates-verdugo.js.map +1 -1
  23. package/build/rules/remove-person-from-unit.js.map +1 -1
  24. package/build/rules/set-address.js.map +1 -1
  25. package/build/rules/set-communication-channels-from-radio-names.js.map +1 -1
  26. package/build/rules/set-fire-alarm-at-dispatch-from-alarm-level.js.map +1 -1
  27. package/build/rules/set-fire-map-from-map-pages-southern-marin.js.map +1 -1
  28. package/build/rules/set-format-units-pulsepoint.js.map +1 -1
  29. package/build/store.js +10 -4
  30. package/build/store.js.map +1 -1
  31. package/build/test/domain.js.map +1 -1
  32. package/build/test/index.js +94 -21
  33. package/build/test/index.js.map +1 -1
  34. package/build/test/mock.js +117 -34
  35. package/build/test/mock.js.map +1 -1
  36. package/build/test/rules/join-call-type-priority.js +16 -2
  37. package/build/test/rules/join-call-type-priority.js.map +1 -1
  38. package/build/test/rules/join-call-type-sacramento.js +36 -0
  39. package/build/test/rules/join-call-type-sacramento.js.map +1 -0
  40. package/build/test/rules/map-unit-dates-verdugo.js.map +1 -1
  41. package/build/test/rules/remove-person-from-unit.js.map +1 -1
  42. package/build/test/rules/set-format-units-pulsepoint.js.map +1 -1
  43. package/definitions/domain.d.ts +6 -6
  44. package/definitions/domain.d.ts.map +1 -1
  45. package/definitions/incidentProcessor.d.ts +1 -1
  46. package/definitions/incidentProcessor.d.ts.map +1 -1
  47. package/definitions/index.d.ts +1 -1
  48. package/definitions/index.d.ts.map +1 -1
  49. package/definitions/rules/clean-up-comments.d.ts +2 -2
  50. package/definitions/rules/clean-up-comments.d.ts.map +1 -1
  51. package/definitions/rules/clear-field.d.ts +1 -1
  52. package/definitions/rules/clear-field.d.ts.map +1 -1
  53. package/definitions/rules/close-incident-matching-incident-number.d.ts.map +1 -1
  54. package/definitions/rules/copy-incident-number.d.ts.map +1 -1
  55. package/definitions/rules/copy-location-comment.d.ts.map +1 -1
  56. package/definitions/rules/index.d.ts.map +1 -1
  57. package/definitions/rules/join-call-type-priority.d.ts +4 -3
  58. package/definitions/rules/join-call-type-priority.d.ts.map +1 -1
  59. package/definitions/rules/join-call-type-sacramento.d.ts +10 -0
  60. package/definitions/rules/join-call-type-sacramento.d.ts.map +1 -0
  61. package/definitions/rules/map-unit-dates-verdugo.d.ts.map +1 -1
  62. package/definitions/rules/remove-person-from-unit.d.ts +3 -3
  63. package/definitions/rules/remove-person-from-unit.d.ts.map +1 -1
  64. package/definitions/rules/set-address.d.ts.map +1 -1
  65. package/definitions/rules/set-communication-channels-from-radio-names.d.ts.map +1 -1
  66. package/definitions/rules/set-format-units-pulsepoint.d.ts.map +1 -1
  67. package/definitions/setIncidentType.d.ts +2 -2
  68. package/definitions/setIncidentType.d.ts.map +1 -1
  69. package/definitions/store.d.ts +34 -2
  70. package/definitions/store.d.ts.map +1 -1
  71. package/definitions/test/mock.d.ts +3 -1
  72. package/definitions/test/mock.d.ts.map +1 -1
  73. package/definitions/test/rules/join-call-type-sacramento.d.ts +2 -0
  74. package/definitions/test/rules/join-call-type-sacramento.d.ts.map +1 -0
  75. package/definitions/test/rules/map-unit-dates-verdugo.d.ts.map +1 -1
  76. package/definitions/types.d.ts +2 -42
  77. package/definitions/types.d.ts.map +1 -1
  78. package/package.json +17 -20
  79. package/src/domain.ts +30 -38
  80. package/src/incidentProcessor.ts +9 -10
  81. package/src/ruleProcessorLegacy.js +1 -1
  82. package/src/rules/clean-up-comments.ts +9 -9
  83. package/src/rules/clear-field.ts +1 -1
  84. package/src/rules/close-incident-after-hours.ts +1 -1
  85. package/src/rules/close-incident-matching-incident-number.ts +3 -3
  86. package/src/rules/close-incident-of-certain-type.ts +1 -1
  87. package/src/rules/copy-incident-number.ts +2 -2
  88. package/src/rules/copy-location-comment.ts +3 -3
  89. package/src/rules/index.ts +14 -4
  90. package/src/rules/join-call-type-priority.ts +23 -14
  91. package/src/rules/join-call-type-sacramento.ts +51 -0
  92. package/src/rules/map-unit-dates-verdugo.ts +3 -3
  93. package/src/rules/remove-person-from-unit.ts +6 -5
  94. package/src/rules/set-address.ts +4 -4
  95. package/src/rules/set-communication-channels-from-radio-names.ts +2 -2
  96. package/src/rules/set-fire-alarm-at-dispatch-from-alarm-level.ts +4 -4
  97. package/src/rules/set-fire-map-from-map-pages-southern-marin.ts +3 -3
  98. package/src/rules/set-format-units-pulsepoint.ts +4 -4
  99. package/src/store.ts +16 -10
  100. package/src/test/domain.ts +17 -17
  101. package/src/test/index.ts +117 -26
  102. package/src/test/mock.ts +141 -55
  103. package/src/test/rules/join-call-type-priority.ts +18 -2
  104. package/src/test/rules/join-call-type-sacramento.ts +40 -0
  105. package/src/test/rules/map-unit-dates-verdugo.ts +2 -2
  106. package/src/test/rules/remove-person-from-unit.ts +2 -2
  107. package/src/test/rules/set-format-units-pulsepoint.ts +3 -3
  108. package/src/types.ts +0 -51
  109. package/test.sh +1 -1
@@ -2,7 +2,8 @@ import _ from "lodash";
2
2
 
3
3
  import { CADIncident } from "tabletcommand-backend-models";
4
4
  import { IncidentRule, IncidentRuleChange } from ".";
5
- import { CADPerson, CADUnit } from "../types";
5
+ import { CADUnitType } from "tabletcommand-backend-models/definitions/types/cad-incident";
6
+ import { CADPersonSchemaType } from "tabletcommand-backend-models/definitions/types/shared-incident";
6
7
 
7
8
  export type FieldToClear = keyof CADIncident;
8
9
 
@@ -24,7 +25,7 @@ export class IncidentRuleRemovePersonFromUnit implements IncidentRule {
24
25
 
25
26
  let ruleMatched = false;
26
27
 
27
- _.each(item.Unit as CADUnit[], function(unit: CADUnit) {
28
+ _.each(item.Unit as CADUnitType[], function(unit) {
28
29
  if (!_.isObject(unit)) {
29
30
  return;
30
31
  }
@@ -33,9 +34,9 @@ export class IncidentRuleRemovePersonFromUnit implements IncidentRule {
33
34
  return;
34
35
  }
35
36
 
36
- const revisedItems: CADPerson[] = [];
37
+ const revisedItems: CADPersonSchemaType[] = [];
37
38
  let personnelCount = (_.isNumber(unit.PersonnelCount) && _.isFinite(unit.PersonnelCount) && unit.PersonnelCount > 0) ? unit.PersonnelCount : 0;
38
- _.each(unit.Personnel, function(person: CADPerson) {
39
+ _.each(unit.Personnel, function(person: CADPersonSchemaType) {
39
40
  if (!_.isObject(person) || !_.isString(person.PersonnelName)) {
40
41
  return;
41
42
  }
@@ -66,7 +67,7 @@ export class IncidentRuleRemovePersonFromUnit implements IncidentRule {
66
67
  }
67
68
  }
68
69
 
69
- export function shouldRemovePerson(item: Partial<CADPerson>): boolean {
70
+ export function shouldRemovePerson(item: Partial<CADPersonSchemaType>): boolean {
70
71
  if (!_.isString(item.PersonnelName)) {
71
72
  return false;
72
73
  }
@@ -1,9 +1,9 @@
1
- import { CADComment } from "../types";
2
1
  import _ from "lodash";
3
2
  import moment from "moment-timezone";
4
3
 
5
4
  import { CADIncident } from "tabletcommand-backend-models";
6
5
  import { IncidentRule, IncidentRuleChange } from ".";
6
+ import { CADCommentType } from "tabletcommand-backend-models/definitions/types/cad-incident";
7
7
 
8
8
  export class IncidentRuleSetAddress implements IncidentRule {
9
9
  name = "Set Address";
@@ -24,15 +24,15 @@ export class IncidentRuleSetAddress implements IncidentRule {
24
24
  this.changed = this.matched;
25
25
  item.full_address = address;
26
26
 
27
- const addrComment: Partial<CADComment> = {
27
+ const addrComment: Partial<CADCommentType> = {
28
28
  Comment: `Address: ${address}`,
29
29
  CommentDateTime: moment(atDate).format("YYYY-MM-DDTHH:mm:ssZZ"),
30
30
  CommentSource: "TC",
31
31
  };
32
32
  if (!_.isArray(item.Comment)) {
33
33
  item.Comment = [];
34
- }
35
- item.Comment?.push(addrComment as CADComment); // Silence typescript/mongo mismatch
34
+ }
35
+ item.Comment?.push(addrComment as CADCommentType); // Silence typescript/mongo mismatch
36
36
 
37
37
  this.changes.push({
38
38
  name: this.name,
@@ -1,8 +1,8 @@
1
- import { CADUnit } from "../types";
2
1
  import _ from "lodash";
3
2
 
4
3
  import { CADIncident } from "tabletcommand-backend-models";
5
4
  import { IncidentRule, IncidentRuleChange } from ".";
5
+ import { CADUnitType } from "tabletcommand-backend-models/definitions/types/cad-incident";
6
6
 
7
7
  export class IncidentRuleSetCommunicationChannelsFromRadioNames implements IncidentRule {
8
8
  name = "Set Communication Channels From Radio Names";
@@ -29,7 +29,7 @@ export class IncidentRuleSetCommunicationChannelsFromRadioNames implements Incid
29
29
  return item;
30
30
  }
31
31
 
32
- const incomingRadioNames = _.map(item.Unit as Partial<CADUnit>[], (item: Partial<CADUnit>) => {
32
+ const incomingRadioNames = _.map(item.Unit as Partial<CADUnitType>[], (item: Partial<CADUnitType>) => {
33
33
  if (!_.isString(item.UnitID)) {
34
34
  return "";
35
35
  }
@@ -1,7 +1,7 @@
1
1
  import _ from "lodash";
2
2
  import { CADIncident } from "tabletcommand-backend-models";
3
3
  import { IncidentRule, IncidentRuleChange } from ".";
4
- import { CADUnit } from "../types";
4
+ import { CADUnitType } from "tabletcommand-backend-models/definitions/types/cad-incident";
5
5
 
6
6
  export class IncidentRuleSetAlarmAtDispatchFromAlarmLevel implements IncidentRule {
7
7
  name = "Set Unit.AlarmAtDispatch from Incident.AlarmLevel";
@@ -27,8 +27,8 @@ export class IncidentRuleSetAlarmAtDispatchFromAlarmLevel implements IncidentRul
27
27
  const change: Record<string, string> = {};
28
28
 
29
29
  // Process if unit is from Stream
30
- if (_.isArray(item.Unit as CADUnit[])) {
31
- (item.Unit as CADUnit[]).forEach((unit: CADUnit) => {
30
+ if (_.isArray(item.Unit as CADUnitType[])) {
31
+ (item.Unit as CADUnitType[]).forEach((unit) => {
32
32
  if (_.isString(unit.AlarmAtDispatch) && unit.AlarmAtDispatch !== "") {
33
33
  return;
34
34
  }
@@ -41,7 +41,7 @@ export class IncidentRuleSetAlarmAtDispatchFromAlarmLevel implements IncidentRul
41
41
 
42
42
  // Process if unit is from Incident
43
43
  if (_.isArray(item.units)) {
44
- item.units.forEach((unit: CADUnit) => {
44
+ item.units.forEach((unit: CADUnitType) => {
45
45
  if (_.isString(unit.AlarmAtDispatch) && unit.AlarmAtDispatch !== "") {
46
46
  return;
47
47
  }
@@ -3,7 +3,7 @@ import moment from "moment-timezone";
3
3
 
4
4
  import { CADIncident } from "tabletcommand-backend-models";
5
5
  import { IncidentRule, IncidentRuleChange } from ".";
6
- import { CADComment } from "../types";
6
+ import { CADCommentType } from "tabletcommand-backend-models/definitions/types/cad-incident";
7
7
 
8
8
  export class IncidentRuleSetFireMapFromMapPagesSouthernMarin implements IncidentRule {
9
9
  name = "Set Fire Map From Map Pages Southern Marin";
@@ -30,7 +30,7 @@ export class IncidentRuleSetFireMapFromMapPagesSouthernMarin implements Incident
30
30
  item.FireMap = fireMap;
31
31
  }
32
32
 
33
- const extraComment: Partial<CADComment> = {
33
+ const extraComment: Partial<CADCommentType> = {
34
34
  Comment: `MapGrid: ${_.trim(previousMapPage)}`,
35
35
  CommentDateTime: moment(atDate).format("YYYY-MM-DDTHH:mm:ssZZ"),
36
36
  CommentSource: "TC",
@@ -39,7 +39,7 @@ export class IncidentRuleSetFireMapFromMapPagesSouthernMarin implements Incident
39
39
  if (!_.isArray(item.Comment)) {
40
40
  item.Comment = [];
41
41
  }
42
- item.Comment?.push(extraComment as CADComment); // Silence typescript/mongo mismatch
42
+ item.Comment?.push(extraComment as CADCommentType); // Silence typescript/mongo mismatch
43
43
 
44
44
  this.changes.push({
45
45
  name: this.name,
@@ -1,8 +1,8 @@
1
1
  import _ from "lodash";
2
2
 
3
3
  import { CADIncident } from "tabletcommand-backend-models";
4
- import { CADUnit } from "../types";
5
4
  import { IncidentRule, IncidentRuleChange } from ".";
5
+ import { CADUnitType } from "tabletcommand-backend-models/definitions/types/cad-incident";
6
6
 
7
7
  export class IncidentRuleSetFormatUnitsPulsePoint implements IncidentRule {
8
8
  name = "Format Units PulsePoint";
@@ -16,11 +16,11 @@ export class IncidentRuleSetFormatUnitsPulsePoint implements IncidentRule {
16
16
 
17
17
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
18
  apply(item: Partial<CADIncident>, _atDate: Date): Partial<CADIncident> {
19
- const tempArray: Partial<CADUnit>[] = [];
19
+ const tempArray: Partial<CADUnitType>[] = [];
20
20
  if (_.isPlainObject(item.Unit)) {
21
- _.each(item.Unit as Array<Partial<CADUnit>>, (value) => {
21
+ _.each(item.Unit as Array<Partial<CADUnitType>>, (value) => {
22
22
  if (_.isPlainObject(value)) {
23
- const tempObject: Partial<CADUnit> = _.cloneDeep(value);
23
+ const tempObject: Partial<CADUnitType> = _.cloneDeep(value);
24
24
  if (_.isString(value.UnitDispatchDateTime)) {
25
25
  tempObject.TimeDispatched = value.UnitDispatchDateTime;
26
26
  delete tempObject.UnitDispatchDateTime;
package/src/store.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import debug_module from "debug";
2
2
  import _ from "lodash";
3
- import mongoose, {
3
+ import {
4
4
  FilterQuery,
5
- MongooseFilterQuery,
5
+ SortOrder
6
6
  } from "mongoose";
7
7
  import * as Sentry from "@sentry/node";
8
8
 
@@ -61,9 +61,9 @@ export default function storeModule({ models }: {
61
61
  }
62
62
 
63
63
  async function previousIncident(incident: Partial<CADIncident>, department: Partial<Department>): Promise<Partial<CADIncident>> {
64
- const query: MongooseFilterQuery<CADIncident> = {
64
+ const query: FilterQuery<CADIncident> = {
65
65
  IncidentNumber: incident.IncidentNumber,
66
- departmentId: (department._id as mongoose.Types.ObjectId).toString(),
66
+ departmentId: department._id?.toString(),
67
67
  };
68
68
 
69
69
  // Remove lean, if found document
@@ -100,7 +100,7 @@ export default function storeModule({ models }: {
100
100
  }
101
101
  };
102
102
  // By default, sort items old to new
103
- let sortBy = {
103
+ let sortBy: Record<string, SortOrder> = {
104
104
  createdAt: 1,
105
105
  // Adding _id to get a guaranteed order if createdAt are equal.
106
106
  // Sorting by _id only would not be enough because although they are roughly consecutive,
@@ -132,7 +132,7 @@ export default function storeModule({ models }: {
132
132
 
133
133
  async function previousIncidentsV1(incident: Partial<CADIncident>, department: Partial<Department>) {
134
134
  const incidentValid = _.isObject(incident) && _.isString(incident.IncidentNumber);
135
- const departmentValid: boolean = _.isObject(department) && (department._id as mongoose.Types.ObjectId) !== null;
135
+ const departmentValid: boolean = _.isObject(department) && !!department._id;
136
136
  const valid: boolean = incidentValid && departmentValid;
137
137
  let incidents: Partial<CADIncident>[] = [];
138
138
  if (!valid) {
@@ -140,9 +140,9 @@ export default function storeModule({ models }: {
140
140
  return incidents;
141
141
  }
142
142
 
143
- const query: MongooseFilterQuery<CADIncident> = {
143
+ const query: FilterQuery<CADIncident> = {
144
144
  IncidentNumber: incident.IncidentNumber,
145
- departmentId: (department._id as mongoose.Types.ObjectId).toString(),
145
+ departmentId: department._id?.toString(),
146
146
  };
147
147
 
148
148
  const dbIncidents = await models.CADIncident.find(query).lean();
@@ -161,8 +161,8 @@ export default function storeModule({ models }: {
161
161
  async function saveIncidentV1(item: Partial<CADIncident>) {
162
162
  debug(`Saving CADIncident:${JSON.stringify(item)}.`);
163
163
  const toSave = new models.CADIncident(item);
164
- const query: MongooseFilterQuery<CADIncident> = {
165
- _id: (toSave._id as mongoose.Types.ObjectId),
164
+ const query: FilterQuery<CADIncident> = {
165
+ _id: (toSave._id),
166
166
  };
167
167
  const replaceOpts = { upsert: true };
168
168
  const res = await models.CADIncident.replaceOne(query, toSave).setOptions(replaceOpts) as unknown;
@@ -171,6 +171,10 @@ export default function storeModule({ models }: {
171
171
  return toSave;
172
172
  }
173
173
 
174
+ async function convertItemWithPersonnelToModel(mergedItemWithPersonnel: Partial<CADIncident>) {
175
+ return new models.CADIncident(mergedItemWithPersonnel);
176
+ }
177
+
174
178
  return {
175
179
  retrievePersonnel,
176
180
  previousIncident,
@@ -180,6 +184,8 @@ export default function storeModule({ models }: {
180
184
 
181
185
  previousIncidentsV1,
182
186
  saveIncidentV1,
187
+
188
+ convertItemWithPersonnelToModel,
183
189
  };
184
190
  }
185
191
 
@@ -3,8 +3,8 @@ import "mocha";
3
3
  import _ from "lodash";
4
4
 
5
5
  import domain from "../domain";
6
- import { CADComment, CADUnit } from "../types";
7
6
  import { CADIncident } from "tabletcommand-backend-models";
7
+ import { CADCommentType, CADUnitType } from "tabletcommand-backend-models/definitions/types/cad-incident";
8
8
 
9
9
  it("domain.mergePersonnel resolves to correct unit personnel counts", function() {
10
10
  // Need to run verify/personnel-import.js on server-status locally
@@ -46,7 +46,7 @@ it("domain.mergePersonnel resolves to correct unit personnel counts", function()
46
46
  }
47
47
  ]
48
48
  }
49
- ] as CADUnit[];
49
+ ] as CADUnitType[];
50
50
 
51
51
  const personnelPartial = [
52
52
  //
@@ -59,14 +59,14 @@ it("domain.mergePersonnel resolves to correct unit personnel counts", function()
59
59
  radioNames: ["Z1"],
60
60
  radios: [
61
61
  {
62
- radioName: "Z1",
63
- active: true,
64
- source: ""
65
- },
62
+ radioName: "Z1",
63
+ active: true,
64
+ source: ""
65
+ },
66
66
  {
67
- radioName: "BBBB123",
68
- active: false,
69
- source: ""
67
+ radioName: "BBBB123",
68
+ active: false,
69
+ source: ""
70
70
  }
71
71
  ],
72
72
  shiftStartTime: 1559446299,
@@ -96,7 +96,7 @@ it("domain.mergePersonnel resolves to correct unit personnel counts", function()
96
96
  radioName: "Z0",
97
97
  active: true,
98
98
  source: ""
99
- },
99
+ },
100
100
  {
101
101
  radioName: "Z1",
102
102
  active: true,
@@ -190,7 +190,7 @@ describe("mergeIncidents", function() {
190
190
  const unit1 = {
191
191
  UnitDispatchNumber: "1",
192
192
  UnitID: "E1"
193
- } as CADUnit;
193
+ } as CADUnitType;
194
194
  const c1 = {
195
195
  Comment: "MapGrid: Grid 4158/P.33",
196
196
  CommentDateTime: "2018-07-20T06:33:28+0000",
@@ -211,13 +211,13 @@ describe("mergeIncidents", function() {
211
211
  const unit2 = {
212
212
  UnitDispatchNumber: "2",
213
213
  UnitID: "E2"
214
- } as CADUnit;
214
+ } as CADUnitType;
215
215
 
216
216
  const unit3 = {
217
217
  UnitDispatchNumber: "1",
218
218
  UnitID: "E1",
219
219
  Time: "2014-07-26T07:19:00-0700"
220
- } as unknown as CADUnit;
220
+ } as unknown as CADUnitType;
221
221
  const c2 = {
222
222
  Comment: "MapGrid: Grid 4158/P.33",
223
223
  CommentDateTime: "2018-07-20T06:33:30+0000",
@@ -297,7 +297,7 @@ describe("mergeIncidents", function() {
297
297
  Time: "2014-07-26T07:19:00-0700",
298
298
  uuid: "cb91ff3c-5804-4593-961a-7868b96f0ba9"
299
299
  };
300
- const units = [unit1, unit2, unit3] as CADUnit[];
300
+ const units = [unit1, unit2, unit3] as CADUnitType[];
301
301
 
302
302
  const mergedItems = domain.mergeUnitsV3(units);
303
303
  let unit1isComplete = false;
@@ -346,7 +346,7 @@ describe("mergeIncidents", function() {
346
346
  "TimeCleared": null,
347
347
  "TimeArrived": "2023-05-01T17:18:56-07:00"
348
348
  }
349
- ] as unknown as CADUnit[];
349
+ ] as unknown as CADUnitType[];
350
350
 
351
351
  const mergedItems = domain.mergeUnitsV3(units);
352
352
  assert.equal(mergedItems.length, units.length, "Same number of units");
@@ -377,7 +377,7 @@ describe("mergeIncidents", function() {
377
377
  CommentDateTime: "2018-07-20T06:33:34+0000",
378
378
  CommentSource: "TC"
379
379
  }
380
- ] as CADComment[];
380
+ ] as CADCommentType[];
381
381
 
382
382
  const mergedItems = domain.mergeCommentsV3(comments);
383
383
  let c1isComplete = false;
@@ -429,7 +429,7 @@ describe("mergeIncidents", function() {
429
429
  c2,
430
430
  c3,
431
431
  c3
432
- ] as CADComment[];
432
+ ] as CADCommentType[];
433
433
 
434
434
  const mergedItems = domain.mergeCommentsV3(comments);
435
435
  assert.equal(mergedItems.length, 2, "Comment count should be the same");
package/src/test/index.ts CHANGED
@@ -4,7 +4,6 @@ import _ from "lodash";
4
4
  import * as modelsModule from "tabletcommand-backend-models";
5
5
 
6
6
  import {
7
- CADUnit,
8
7
  HandleProcessIncidentRequestResult,
9
8
  } from "../types";
10
9
 
@@ -13,6 +12,7 @@ import {
13
12
  indexFile,
14
13
  } from "../index";
15
14
  import mockModule from "./mock";
15
+ import { CADUnitType } from "tabletcommand-backend-models/definitions/types/cad-incident";
16
16
 
17
17
  let mock: ReturnType<typeof mockModule>;
18
18
  let incidentProcessor: IncidentProcessorModule;
@@ -27,7 +27,6 @@ describe("index", function() {
27
27
  mongoose,
28
28
  models
29
29
  } = await modelsModule.connect(process.env.NODE_MONGO_URL || "");
30
- mongoose.set("useFindAndModify", false);
31
30
 
32
31
  mock = mockModule({
33
32
  mongoose,
@@ -144,7 +143,7 @@ describe("index", function() {
144
143
  }
145
144
 
146
145
  it("process stream through legacy", async function() {
147
- const departmentId = mock.departmentAlameda._id as string;
146
+ const departmentId = mock.departmentAlameda._id.toString();
148
147
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
149
148
  const streamItem = _.first(existingStreamItems);
150
149
 
@@ -158,7 +157,7 @@ describe("index", function() {
158
157
  });
159
158
 
160
159
  it("process stream through correction", async function() {
161
- const departmentId = mock.departmentAlameda._id as string;
160
+ const departmentId = mock.departmentAlameda._id.toString();
162
161
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
163
162
  const streamItem = _.first(existingStreamItems);
164
163
 
@@ -191,7 +190,7 @@ describe("index", function() {
191
190
  }
192
191
 
193
192
  it("process stream through legacy", async function() {
194
- const departmentId = mock.departmentCalfireCZU._id as string;
193
+ const departmentId = mock.departmentCalfireCZU._id.toString();
195
194
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
196
195
  const streamItem = _.first(existingStreamItems);
197
196
 
@@ -205,7 +204,7 @@ describe("index", function() {
205
204
  });
206
205
 
207
206
  it("process stream through correction", async function() {
208
- const departmentId = mock.departmentCalfireCZU._id as string;
207
+ const departmentId = mock.departmentCalfireCZU._id.toString();
209
208
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
210
209
  const streamItem = _.first(existingStreamItems);
211
210
 
@@ -238,7 +237,7 @@ describe("index", function() {
238
237
  }
239
238
 
240
239
  it("process stream through legacy", async function() {
241
- const departmentId = mock.departmentCalfireLNU._id as string;
240
+ const departmentId = mock.departmentCalfireLNU._id.toString();
242
241
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
243
242
  const streamItem = _.first(existingStreamItems);
244
243
 
@@ -252,7 +251,7 @@ describe("index", function() {
252
251
  });
253
252
 
254
253
  it("process stream through correction", async function() {
255
- const departmentId = mock.departmentCalfireLNU._id as string;
254
+ const departmentId = mock.departmentCalfireLNU._id.toString();
256
255
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
257
256
  const streamItem = _.first(existingStreamItems);
258
257
 
@@ -284,7 +283,7 @@ describe("index", function() {
284
283
 
285
284
  it("process stream through legacy", async function() {
286
285
  const department = mock.departmentClarkCounty;
287
- const departmentId = department._id as string;
286
+ const departmentId = department._id.toString();
288
287
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
289
288
  const streamItem = _.first(existingStreamItems);
290
289
 
@@ -299,7 +298,54 @@ describe("index", function() {
299
298
 
300
299
  it("process stream through correction", async function() {
301
300
  const department = mock.departmentClarkCounty;
302
- const departmentId = department._id as string;
301
+ const departmentId = department._id.toString();
302
+ const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
303
+ const streamItem = _.first(existingStreamItems);
304
+
305
+ if (!streamItem) {
306
+ assert.fail("Expecting a stream item");
307
+ return;
308
+ }
309
+
310
+ const sut = await incidentProcessor.handleProcessIncidentRequestCorrection(streamItem.incidentNumber, department, atDate);
311
+ validateRulesResult(sut);
312
+ });
313
+ });
314
+
315
+ context("CONFIRE Regional Emergency Communications - San Bernardino County CA", function() {
316
+ const atDate = new Date();
317
+ const sampleIncidentNumber = "Confire-SB-0001";
318
+
319
+ function validateRulesResult(sut: HandleProcessIncidentRequestResult) {
320
+ if ("error" in sut) {
321
+ assert.fail(sut.error.toString());
322
+ } else {
323
+ const {
324
+ incident
325
+ } = sut;
326
+
327
+ assert.strictEqual(incident?.AgencyIncidentCallTypeDescription, "SHORTNESS OF BREATH (C3)");
328
+ }
329
+ }
330
+
331
+ it("process stream through legacy", async function() {
332
+ const department = mock.departmentConfire;
333
+ const departmentId = department._id.toString();
334
+ const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
335
+ const streamItem = _.first(existingStreamItems);
336
+
337
+ if (!streamItem) {
338
+ assert.fail("Expecting a stream item");
339
+ return;
340
+ }
341
+
342
+ const sut = await incidentProcessor.handleProcessIncidentRequestLegacy(streamItem, department, atDate);
343
+ validateRulesResult(sut);
344
+ });
345
+
346
+ it("process stream through correction", async function() {
347
+ const department = mock.departmentConfire;
348
+ const departmentId = department._id.toString();
303
349
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
304
350
  const streamItem = _.first(existingStreamItems);
305
351
 
@@ -326,11 +372,11 @@ describe("index", function() {
326
372
  } = sut;
327
373
 
328
374
  assert.equal(incident?.AgencyIncidentCallTypeDescription, "Structure Fire - 2A", "Should match call type description");
329
- const unitT13 = _.first((incident?.units ?? []).filter((u: CADUnit) => u.UnitID === "T13"));
375
+ const unitT13 = _.first((incident?.units ?? []).filter((u: CADUnitType) => u.UnitID === "T13"));
330
376
  assert.isObject(unitT13);
331
377
  assert.equal(unitT13?.AlarmAtDispatch, incident?.AlarmLevel);
332
378
 
333
- const unitBC2 = _.first((incident?.units ?? []).filter((u: CADUnit) => u.UnitID === "BC2"));
379
+ const unitBC2 = _.first((incident?.units ?? []).filter((u: CADUnitType) => u.UnitID === "BC2"));
334
380
  assert.isObject(unitBC2);
335
381
  assert.equal(unitBC2?.AlarmAtDispatch, "1");
336
382
  }
@@ -338,7 +384,7 @@ describe("index", function() {
338
384
 
339
385
  it("process stream through legacy", async function() {
340
386
  const department = mock.departmentJacksonCountyTest;
341
- const departmentId = department._id as string;
387
+ const departmentId = department._id.toString();
342
388
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
343
389
  const streamItem = _.first(existingStreamItems);
344
390
 
@@ -353,7 +399,54 @@ describe("index", function() {
353
399
 
354
400
  it("process stream through correction", async function() {
355
401
  const department = mock.departmentJacksonCountyTest;
356
- const departmentId = department._id as string;
402
+ const departmentId = department._id.toString();
403
+ const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
404
+ const streamItem = _.first(existingStreamItems);
405
+
406
+ if (!streamItem) {
407
+ assert.fail("Expecting a stream item");
408
+ return;
409
+ }
410
+
411
+ const sut = await incidentProcessor.handleProcessIncidentRequestCorrection(streamItem.incidentNumber, department, atDate);
412
+ validateRulesResult(sut);
413
+ });
414
+ });
415
+
416
+ context("Sacramento Regional Fire Communications Center", function() {
417
+ const atDate = new Date();
418
+ const sampleIncidentNumber = "Sacramento-SB-0001";
419
+
420
+ function validateRulesResult(sut: HandleProcessIncidentRequestResult) {
421
+ if ("error" in sut) {
422
+ assert.fail(sut.error.toString());
423
+ } else {
424
+ const {
425
+ incident
426
+ } = sut;
427
+
428
+ assert.strictEqual(incident?.AgencyIncidentCallTypeDescription, "C2 - PUBLIC ASSISTANCE");
429
+ }
430
+ }
431
+
432
+ it("process stream through legacy", async function() {
433
+ const department = mock.departmentSacramento;
434
+ const departmentId = department._id.toString();
435
+ const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
436
+ const streamItem = _.first(existingStreamItems);
437
+
438
+ if (!streamItem) {
439
+ assert.fail("Expecting a stream item");
440
+ return;
441
+ }
442
+
443
+ const sut = await incidentProcessor.handleProcessIncidentRequestLegacy(streamItem, department, atDate);
444
+ validateRulesResult(sut);
445
+ });
446
+
447
+ it("process stream through correction", async function() {
448
+ const department = mock.departmentSacramento;
449
+ const departmentId = department._id.toString();
357
450
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
358
451
  const streamItem = _.first(existingStreamItems);
359
452
 
@@ -397,7 +490,7 @@ describe("index", function() {
397
490
  }
398
491
 
399
492
  it("process stream through legacy", async function() {
400
- const departmentId = mock.departmentSanMateoCounty._id as string;
493
+ const departmentId = mock.departmentSanMateoCounty._id.toString();
401
494
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
402
495
  const streamItem = _.first(existingStreamItems);
403
496
 
@@ -411,7 +504,7 @@ describe("index", function() {
411
504
  });
412
505
 
413
506
  it("process stream through correction", async function() {
414
- const departmentId = mock.departmentSanMateoCounty._id as string;
507
+ const departmentId = mock.departmentSanMateoCounty._id.toString();
415
508
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
416
509
  const streamItem = _.first(existingStreamItems);
417
510
 
@@ -443,7 +536,7 @@ describe("index", function() {
443
536
  }
444
537
 
445
538
  it("process stream through legacy", async function() {
446
- const departmentId = mock.departmentSantaCruzRegional._id as string;
539
+ const departmentId = mock.departmentSantaCruzRegional._id.toString();
447
540
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
448
541
  const streamItem = _.first(existingStreamItems);
449
542
 
@@ -457,7 +550,7 @@ describe("index", function() {
457
550
  });
458
551
 
459
552
  it("process stream through correction", async function() {
460
- const departmentId = mock.departmentSantaCruzRegional._id as string;
553
+ const departmentId = mock.departmentSantaCruzRegional._id.toString();
461
554
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
462
555
  const streamItem = _.first(existingStreamItems);
463
556
 
@@ -497,21 +590,19 @@ describe("index", function() {
497
590
  }
498
591
 
499
592
  it("process stream through legacy", async function() {
500
- const departmentId = mock.departmentSouthernMarin._id as string;
593
+ const departmentId = mock.departmentSouthernMarin._id.toString();
501
594
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
502
595
  const streamItem = _.first(existingStreamItems);
503
-
504
596
  if (!streamItem) {
505
597
  assert.fail("Expecting a stream item");
506
598
  return;
507
599
  }
508
-
509
600
  const sut = await incidentProcessor.handleProcessIncidentRequestLegacy(streamItem, mock.departmentSouthernMarin, atDate);
510
601
  validateRulesResult(sut);
511
602
  });
512
603
 
513
604
  it("process stream through correction", async function() {
514
- const departmentId = mock.departmentSouthernMarin._id as string;
605
+ const departmentId = mock.departmentSouthernMarin._id.toString();
515
606
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
516
607
  const streamItem = _.first(existingStreamItems);
517
608
 
@@ -544,7 +635,7 @@ describe("index", function() {
544
635
  }
545
636
 
546
637
  it("process stream through legacy", async function() {
547
- const departmentId = mock.departmentVerdugo._id as string;
638
+ const departmentId = mock.departmentVerdugo._id.toString();
548
639
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
549
640
  const streamItem = _.first(existingStreamItems);
550
641
 
@@ -558,7 +649,7 @@ describe("index", function() {
558
649
  });
559
650
 
560
651
  it("process stream through correction", async function() {
561
- const departmentId = mock.departmentVerdugo._id as string;
652
+ const departmentId = mock.departmentVerdugo._id.toString();
562
653
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
563
654
  const streamItem = _.first(existingStreamItems);
564
655
 
@@ -590,7 +681,7 @@ describe("index", function() {
590
681
 
591
682
  it("process stream through legacy", async function() {
592
683
  const department = mock.departmentYolo;
593
- const departmentId = department._id as string;
684
+ const departmentId = department._id.toString();
594
685
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
595
686
  const streamItem = _.first(existingStreamItems);
596
687
 
@@ -605,7 +696,7 @@ describe("index", function() {
605
696
 
606
697
  it("process stream through correction", async function() {
607
698
  const department = mock.departmentYolo;
608
- const departmentId = department._id as string;
699
+ const departmentId = department._id.toString();
609
700
  const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
610
701
  const streamItem = _.first(existingStreamItems);
611
702