tabletcommand-incident 0.6.7 → 0.6.9
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/domain.js +36 -0
- package/build/domain.js.map +1 -1
- package/build/incidentProcessor.js +8 -3
- package/build/incidentProcessor.js.map +1 -1
- package/build/ruleLegacy/closeIncidentMatchingIncidentNumber.js +1 -0
- package/build/ruleLegacy/closeIncidentMatchingIncidentNumber.js.map +1 -1
- package/build/ruleLegacy/closeIncidentOfCertainType.js +1 -0
- package/build/ruleLegacy/closeIncidentOfCertainType.js.map +1 -1
- package/build/rules/close-incident-matching-incident-number.js +1 -0
- package/build/rules/close-incident-matching-incident-number.js.map +1 -1
- package/build/rules/close-incident-of-certain-type.js +2 -0
- package/build/rules/close-incident-of-certain-type.js.map +1 -1
- package/build/rules/set-common-place-name.js +12 -6
- package/build/rules/set-common-place-name.js.map +1 -1
- package/build/test/domain.js +41 -0
- package/build/test/domain.js.map +1 -1
- package/build/test/index.js +23 -1
- package/build/test/index.js.map +1 -1
- package/build/test/mock.js +67 -11
- package/build/test/mock.js.map +1 -1
- package/build/test/rules/set-common-place-name.js +6 -2
- package/build/test/rules/set-common-place-name.js.map +1 -1
- package/definitions/domain.d.ts.map +1 -1
- package/definitions/incidentProcessor.d.ts.map +1 -1
- package/definitions/ruleLegacy/closeIncidentMatchingIncidentNumber.d.ts.map +1 -1
- package/definitions/ruleLegacy/closeIncidentOfCertainType.d.ts.map +1 -1
- package/definitions/rules/close-incident-matching-incident-number.d.ts.map +1 -1
- package/definitions/rules/close-incident-of-certain-type.d.ts.map +1 -1
- package/definitions/rules/set-common-place-name.d.ts.map +1 -1
- package/definitions/test/mock.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/domain.ts +35 -0
- package/src/incidentProcessor.ts +8 -3
- package/src/ruleLegacy/closeIncidentMatchingIncidentNumber.js +1 -0
- package/src/ruleLegacy/closeIncidentOfCertainType.js +2 -1
- package/src/rules/close-incident-matching-incident-number.ts +1 -0
- package/src/rules/close-incident-of-certain-type.ts +2 -0
- package/src/rules/set-common-place-name.ts +13 -7
- package/src/test/domain.ts +47 -0
- package/src/test/index.ts +30 -1
- package/src/test/mock.ts +66 -14
- package/src/test/rules/set-common-place-name.ts +6 -2
|
@@ -4,7 +4,7 @@ import { CADIncident } from "tabletcommand-backend-models";
|
|
|
4
4
|
import { IncidentRule, IncidentRuleChange } from ".";
|
|
5
5
|
|
|
6
6
|
export class IncidentRuleSetCommonPlaceName implements IncidentRule {
|
|
7
|
-
name = "Set Common Place Name";
|
|
7
|
+
name = "Set Common Place Name Backup";
|
|
8
8
|
matched = false;
|
|
9
9
|
changed = false;
|
|
10
10
|
changes: IncidentRuleChange[] = [];
|
|
@@ -15,10 +15,15 @@ export class IncidentRuleSetCommonPlaceName implements IncidentRule {
|
|
|
15
15
|
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
17
|
apply(item: Partial<CADIncident>, _atDate: Date): Partial<CADIncident> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const commonPlaceName = _.isString(item.CommonPlaceName) ? item.CommonPlaceName?.trim() : "";
|
|
19
|
+
const locationComment = _.isString(item.LocationComment) ? item.LocationComment?.trim() : "";
|
|
20
|
+
item.CommonPlaceNameCopy = commonPlaceName;
|
|
21
|
+
|
|
22
|
+
// This module only copies the original commonPlaceName to CommonPlaceNameCopy
|
|
23
|
+
// A change in merge/flatten is required to accommodate for accounts where
|
|
24
|
+
// LocationComment and CommonPlaceName are not sent in the same request
|
|
25
|
+
|
|
26
|
+
if (commonPlaceName !== "") {
|
|
22
27
|
this.matched = true;
|
|
23
28
|
this.changed = true;
|
|
24
29
|
this.changes.push({
|
|
@@ -26,8 +31,9 @@ export class IncidentRuleSetCommonPlaceName implements IncidentRule {
|
|
|
26
31
|
matched: this.matched,
|
|
27
32
|
changed: this.changed,
|
|
28
33
|
change: {
|
|
29
|
-
CommonPlaceName:
|
|
30
|
-
|
|
34
|
+
CommonPlaceName: commonPlaceName,
|
|
35
|
+
CommonPlaceNameCopy: commonPlaceName,
|
|
36
|
+
LocationComment: locationComment,
|
|
31
37
|
}
|
|
32
38
|
});
|
|
33
39
|
}
|
package/src/test/domain.ts
CHANGED
|
@@ -638,4 +638,51 @@ describe("mergeIncidents", function() {
|
|
|
638
638
|
assert.equal(c?.CallerId, "(123) 456-789");
|
|
639
639
|
assert.equal(c?.UncertaintyRadius, 401);
|
|
640
640
|
});
|
|
641
|
+
|
|
642
|
+
it("merge CommonPlaceName", function() {
|
|
643
|
+
const item1: Partial<CADIncident> = {
|
|
644
|
+
IncidentNumber: "4000",
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
const item2: Partial<CADIncident> = {
|
|
648
|
+
IncidentNumber: "4000",
|
|
649
|
+
LocationComment: "100 Bono Dr",
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
const itemA = domain.mergeIncidentsV3([item1, item2], item1);
|
|
653
|
+
assert.equal(itemA.IncidentNumber, item1.IncidentNumber);
|
|
654
|
+
assert.equal(itemA.CommonPlaceName, "100 Bono Dr");
|
|
655
|
+
|
|
656
|
+
const item3: Partial<CADIncident> = {
|
|
657
|
+
IncidentNumber: "4000",
|
|
658
|
+
CommonPlaceName: "East House",
|
|
659
|
+
CommonPlaceNameCopy: "East House",
|
|
660
|
+
};
|
|
661
|
+
const itemB = domain.mergeIncidentsV3([item1, item2, item3], item1);
|
|
662
|
+
assert.equal(itemB.IncidentNumber, item1.IncidentNumber);
|
|
663
|
+
assert.equal(itemB.CommonPlaceNameCopy, item3.CommonPlaceNameCopy);
|
|
664
|
+
assert.equal(itemB.LocationComment, item2.LocationComment);
|
|
665
|
+
assert.equal(itemB.CommonPlaceName, "100 Bono Dr - East House");
|
|
666
|
+
|
|
667
|
+
const item4: Partial<CADIncident> = {
|
|
668
|
+
IncidentNumber: "4000",
|
|
669
|
+
LocationComment: "200 Bono Dr",
|
|
670
|
+
};
|
|
671
|
+
const itemC = domain.mergeIncidentsV3([item1, item2, item3, item4], item1);
|
|
672
|
+
assert.equal(itemC.IncidentNumber, item1.IncidentNumber);
|
|
673
|
+
assert.equal(itemC.CommonPlaceNameCopy, item3.CommonPlaceNameCopy);
|
|
674
|
+
assert.equal(itemC.LocationComment, item4.LocationComment);
|
|
675
|
+
assert.equal(itemC.CommonPlaceName, "200 Bono Dr - East House");
|
|
676
|
+
|
|
677
|
+
const item5: Partial<CADIncident> = {
|
|
678
|
+
IncidentNumber: "4000",
|
|
679
|
+
CommonPlaceName: "West House",
|
|
680
|
+
CommonPlaceNameCopy: "West House",
|
|
681
|
+
};
|
|
682
|
+
const itemD = domain.mergeIncidentsV3([item1, item2, item3, item4, item5], item1);
|
|
683
|
+
assert.equal(itemD.IncidentNumber, item1.IncidentNumber);
|
|
684
|
+
assert.equal(itemD.CommonPlaceNameCopy, item5.CommonPlaceNameCopy);
|
|
685
|
+
assert.equal(itemD.LocationComment, item4.LocationComment);
|
|
686
|
+
assert.equal(itemD.CommonPlaceName, "200 Bono Dr - West House");
|
|
687
|
+
});
|
|
641
688
|
});
|
package/src/test/index.ts
CHANGED
|
@@ -63,7 +63,6 @@ describe("index", function() {
|
|
|
63
63
|
assert.equal(incident?.CrossStreet1, undefined);
|
|
64
64
|
assert.equal(incident?.CrossStreet2, undefined);
|
|
65
65
|
|
|
66
|
-
// expect CommonPlaceName to be copied from LocationComment
|
|
67
66
|
assert.equal(incident?.CommonPlaceName, expectedCommonPlaceName);
|
|
68
67
|
|
|
69
68
|
// copied here by the IncidentRuleCopyIncidentNumber rule
|
|
@@ -356,6 +355,36 @@ describe("index", function() {
|
|
|
356
355
|
});
|
|
357
356
|
});
|
|
358
357
|
|
|
358
|
+
context("Demo RTS - 0003 - LocationComment/CommonPlaceName changes", function() {
|
|
359
|
+
const atDate = new Date();
|
|
360
|
+
const sampleIncidentNumber = "DEMO-RTS-0003";
|
|
361
|
+
|
|
362
|
+
it("process stream through correction", async function() {
|
|
363
|
+
const department = mock.departmentDemoRTS;
|
|
364
|
+
const departmentId = department._id.toString();
|
|
365
|
+
const existingStreamItems = await mock.getIncidentStreamItems(departmentId, sampleIncidentNumber);
|
|
366
|
+
const streamItem = _.first(existingStreamItems);
|
|
367
|
+
|
|
368
|
+
if (!streamItem) {
|
|
369
|
+
assert.fail("Expecting a stream item");
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const sut1 = await incidentProcessor.handleProcessIncidentRequestCorrection(streamItem.incidentNumber, department, atDate);
|
|
374
|
+
if ("error" in sut1) {
|
|
375
|
+
assert.fail(sut1.error.toString());
|
|
376
|
+
} else {
|
|
377
|
+
const {
|
|
378
|
+
incident,
|
|
379
|
+
} = sut1;
|
|
380
|
+
|
|
381
|
+
assert.equal(incident?.CommonPlaceName, "200 Bono Dr - West Housing");
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// validateRulesResult(sut);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
359
388
|
context("Jackson County - Testing", function() {
|
|
360
389
|
const atDate = new Date();
|
|
361
390
|
const sampleIncidentNumber = "Jackson-County-Test-0001";
|
package/src/test/mock.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
|
-
import { Collection } from "mongodb";
|
|
3
2
|
import {
|
|
4
3
|
BackendModels,
|
|
5
4
|
CADIncident,
|
|
@@ -411,6 +410,57 @@ export default function({
|
|
|
411
410
|
"ClosedDateTime": "2022-10-26T17:19:49-04:00",
|
|
412
411
|
}
|
|
413
412
|
},
|
|
413
|
+
{
|
|
414
|
+
departmentId,
|
|
415
|
+
"incidentNumber": "DEMO-RTS-0003",
|
|
416
|
+
"createdAt": new Date("2022-10-26T22:03:10.101+0000"),
|
|
417
|
+
"payload": {
|
|
418
|
+
"AgencyID": "Demo RTS AgencyId",
|
|
419
|
+
"IncidentNumber": "DEMO-RTS-0003",
|
|
420
|
+
"AgencyIncidentCallTypeDescription": "Test Description 3",
|
|
421
|
+
"EntryDateTime": "2022-10-26T17:09:49-04:00",
|
|
422
|
+
"Longitude": "-115.355705",
|
|
423
|
+
"Latitude": "37.959790",
|
|
424
|
+
"ClosedDateTime": "",
|
|
425
|
+
"LocationComment": "100 Bono Dr",
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
departmentId,
|
|
430
|
+
"incidentNumber": "DEMO-RTS-0003",
|
|
431
|
+
"createdAt": new Date("2022-10-26T22:03:10.201+0000"),
|
|
432
|
+
"payload": {
|
|
433
|
+
"AgencyID": "Demo RTS AgencyId",
|
|
434
|
+
"IncidentNumber": "DEMO-RTS-0003",
|
|
435
|
+
"EntryDateTime": "2022-10-26T17:09:49-04:00",
|
|
436
|
+
"ClosedDateTime": "",
|
|
437
|
+
"CommonPlaceName": "East Housing",
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
departmentId,
|
|
442
|
+
"incidentNumber": "DEMO-RTS-0003",
|
|
443
|
+
"createdAt": new Date("2022-10-26T22:03:10.301+0000"),
|
|
444
|
+
"payload": {
|
|
445
|
+
"AgencyID": "Demo RTS AgencyId",
|
|
446
|
+
"IncidentNumber": "DEMO-RTS-0003",
|
|
447
|
+
"EntryDateTime": "2022-10-26T17:09:49-04:00",
|
|
448
|
+
"ClosedDateTime": "",
|
|
449
|
+
"LocationComment": "200 Bono Dr",
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
departmentId,
|
|
454
|
+
"incidentNumber": "DEMO-RTS-0003",
|
|
455
|
+
"createdAt": new Date("2022-10-26T22:03:10.401+0000"),
|
|
456
|
+
"payload": {
|
|
457
|
+
"AgencyID": "Demo RTS AgencyId",
|
|
458
|
+
"IncidentNumber": "DEMO-RTS-0003",
|
|
459
|
+
"EntryDateTime": "2022-10-26T17:09:49-04:00",
|
|
460
|
+
"ClosedDateTime": "",
|
|
461
|
+
"CommonPlaceName": "West Housing",
|
|
462
|
+
}
|
|
463
|
+
},
|
|
414
464
|
// Jackson County
|
|
415
465
|
{
|
|
416
466
|
departmentId: departmentJacksonCountyTest._id.toString(),
|
|
@@ -840,6 +890,7 @@ export default function({
|
|
|
840
890
|
}
|
|
841
891
|
],
|
|
842
892
|
"closed_unix_date": 0,
|
|
893
|
+
is_closed: false,
|
|
843
894
|
"start_unix_date": 1695905024,
|
|
844
895
|
Comment: [
|
|
845
896
|
{
|
|
@@ -875,27 +926,28 @@ export default function({
|
|
|
875
926
|
process.exit(1);
|
|
876
927
|
}
|
|
877
928
|
|
|
878
|
-
|
|
879
|
-
await flushCollections(items, 0);
|
|
929
|
+
await flushCollections();
|
|
880
930
|
// await mongoose.connection.db.dropDatabase();
|
|
881
931
|
await prepareTestData();
|
|
882
932
|
}
|
|
883
933
|
|
|
884
|
-
async function flushCollections(
|
|
885
|
-
|
|
886
|
-
|
|
934
|
+
async function flushCollections() {
|
|
935
|
+
const modelNames = mongoose.modelNames();
|
|
936
|
+
for (const modelName of modelNames) {
|
|
937
|
+
// debug(`Model ${modelName}`);
|
|
938
|
+
const m = mongoose.model(modelName);
|
|
939
|
+
await m.deleteMany({});
|
|
940
|
+
try {
|
|
941
|
+
await m.syncIndexes();
|
|
942
|
+
} catch (error) {
|
|
943
|
+
console.log(`Failed to sync index ${modelName}`);
|
|
944
|
+
console.error(error);
|
|
945
|
+
process.exit(1);
|
|
946
|
+
}
|
|
887
947
|
}
|
|
888
|
-
|
|
889
|
-
const collection = items[index];
|
|
890
|
-
// console.log(`Emptying ${collection.collectionName}.`);
|
|
891
|
-
await collection.deleteMany({});
|
|
892
|
-
await flushCollections(items, index + 1);
|
|
893
948
|
}
|
|
894
949
|
|
|
895
950
|
async function prepareTestData() {
|
|
896
|
-
// Create indexes
|
|
897
|
-
await models.CADIncident.createIndexes();
|
|
898
|
-
|
|
899
951
|
for (const item of [
|
|
900
952
|
departmentAlameda,
|
|
901
953
|
departmentCalfireLNU,
|
|
@@ -6,12 +6,14 @@ import {
|
|
|
6
6
|
} from "../../rules/set-common-place-name";
|
|
7
7
|
|
|
8
8
|
describe("IncidentRuleSetCommonPlaceName", function describeFunc() {
|
|
9
|
-
it("
|
|
9
|
+
it("if both are present, LocationComment - CommonPlaceName is copied to CommonPlaceName", function() {
|
|
10
10
|
const LocationComment = "1700 Botelho Dr";
|
|
11
|
+
const CommonPlaceName = "SAC HOUSING";
|
|
11
12
|
const testMatchIncidentWithAddress = {
|
|
12
13
|
IncidentNumber: "i1238",
|
|
13
14
|
departmentId: "515",
|
|
14
15
|
LocationComment,
|
|
16
|
+
CommonPlaceName,
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
const dateStr = "2022-12-08T11:53:42.000Z";
|
|
@@ -20,6 +22,8 @@ describe("IncidentRuleSetCommonPlaceName", function describeFunc() {
|
|
|
20
22
|
const result = rule.apply(testMatchIncidentWithAddress, atDate);
|
|
21
23
|
assert.isTrue(rule.matched);
|
|
22
24
|
assert.isTrue(rule.changed);
|
|
23
|
-
assert.equal(result.CommonPlaceName,
|
|
25
|
+
assert.equal(result.CommonPlaceName, CommonPlaceName);
|
|
26
|
+
assert.equal(result.CommonPlaceNameCopy, CommonPlaceName);
|
|
27
|
+
assert.equal(result.LocationComment, LocationComment);
|
|
24
28
|
});
|
|
25
29
|
});
|