tabletcommand-backend-models 7.3.29 → 7.3.30

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 (41) hide show
  1. package/build/constants.js +9 -8
  2. package/build/constants.js.map +1 -1
  3. package/build/index.js +4 -3
  4. package/build/index.js.map +1 -1
  5. package/build/models/department.js +0 -72
  6. package/build/models/department.js.map +1 -1
  7. package/build/models/incident-filter.js +108 -0
  8. package/build/models/incident-filter.js.map +1 -0
  9. package/build/test/department.js +1 -12
  10. package/build/test/department.js.map +1 -1
  11. package/build/test/incident-filter.js +40 -0
  12. package/build/test/incident-filter.js.map +1 -0
  13. package/build/test/mock.js +19 -19
  14. package/build/test/mock.js.map +1 -1
  15. package/build/types/incident-filter.js +3 -0
  16. package/build/types/incident-filter.js.map +1 -0
  17. package/definitions/constants.d.ts +4 -3
  18. package/definitions/constants.d.ts.map +1 -1
  19. package/definitions/index.d.ts +5 -2
  20. package/definitions/index.d.ts.map +1 -1
  21. package/definitions/models/department.d.ts.map +1 -1
  22. package/definitions/models/incident-filter.d.ts +11 -0
  23. package/definitions/models/incident-filter.d.ts.map +1 -0
  24. package/definitions/test/incident-filter.d.ts +2 -0
  25. package/definitions/test/incident-filter.d.ts.map +1 -0
  26. package/definitions/test/mock.d.ts +2 -0
  27. package/definitions/test/mock.d.ts.map +1 -1
  28. package/definitions/types/department.d.ts +1 -16
  29. package/definitions/types/department.d.ts.map +1 -1
  30. package/definitions/types/incident-filter.d.ts +21 -0
  31. package/definitions/types/incident-filter.d.ts.map +1 -0
  32. package/package.json +3 -3
  33. package/src/constants.ts +3 -2
  34. package/src/index.ts +4 -14
  35. package/src/models/department.ts +0 -80
  36. package/src/models/incident-filter.ts +122 -0
  37. package/src/test/department.ts +0 -12
  38. package/src/test/incident-filter.ts +41 -0
  39. package/src/test/mock.ts +22 -20
  40. package/src/types/department.ts +0 -18
  41. package/src/types/incident-filter.ts +25 -0
@@ -0,0 +1,122 @@
1
+ import { Model } from "mongoose";
2
+ import {
3
+ currentDate,
4
+ MongooseModule,
5
+ } from "../helpers";
6
+
7
+ import { IncidentFilterKind } from "../constants";
8
+ import { GeoPolygon } from "../types/common";
9
+ import { IncidentFilterOption, IncidentFilterType } from "../types/incident-filter";
10
+
11
+ export interface IncidentFilter extends IncidentFilterType { }
12
+
13
+ export default async function CADIncidentBlockModule(mongoose: MongooseModule) {
14
+ const { Schema } = mongoose;
15
+
16
+ const GeoPolygonSchema = new Schema<GeoPolygon>({
17
+ type: {
18
+ type: String,
19
+ enum: ["Polygon"],
20
+ required: true
21
+ },
22
+ coordinates: {
23
+ type: [[[Number]]], // Array of arrays of arrays of numbers number[][][]
24
+ required: true
25
+ },
26
+ }, {
27
+ _id: false,
28
+ id: false,
29
+ });
30
+
31
+ const IncidentFilterOptionSchema = new Schema<IncidentFilterOption>({
32
+ name: {
33
+ type: String,
34
+ default: "",
35
+ },
36
+ visible: {
37
+ type: Boolean,
38
+ default: true,
39
+ },
40
+ position: {
41
+ type: Number,
42
+ default: 1,
43
+ },
44
+ area: {
45
+ type: GeoPolygonSchema,
46
+ default: {
47
+ type: "Polygon",
48
+ coordinates: [],
49
+ }
50
+ },
51
+ value: {
52
+ type: String,
53
+ default: "",
54
+ },
55
+ }, {
56
+ _id: false,
57
+ id: false,
58
+ });
59
+
60
+ const modelSchema = new Schema<IncidentFilterType>({
61
+ _id: {
62
+ type: Schema.Types.ObjectId,
63
+ auto: true,
64
+ },
65
+ departmentId: {
66
+ type: String,
67
+ required: true,
68
+ index: true,
69
+ },
70
+
71
+ name: {
72
+ type: String,
73
+ default: "",
74
+ required: true,
75
+ },
76
+ position: {
77
+ type: Number,
78
+ default: 1,
79
+ },
80
+ kind: {
81
+ type: String,
82
+ enum: [
83
+ IncidentFilterKind.AgencyId,
84
+ IncidentFilterKind.AreaUnit,
85
+ IncidentFilterKind.City,
86
+ IncidentFilterKind.County,
87
+ IncidentFilterKind.ReportNumber,
88
+ ],
89
+ },
90
+ options: {
91
+ type: [IncidentFilterOptionSchema],
92
+ default: [],
93
+ },
94
+ createdAt: {
95
+ type: Date,
96
+ default: currentDate,
97
+ },
98
+ updatedAt: {
99
+ type: Date,
100
+ default: currentDate,
101
+ },
102
+ }, {
103
+ timestamps: true,
104
+ autoIndex: false,
105
+ toJSON: {
106
+ virtuals: true,
107
+ versionKey: false,
108
+ }
109
+ });
110
+
111
+ modelSchema.index({
112
+ departmentId: 1,
113
+ IncidentNumber: 1,
114
+ }, {
115
+ name: "departmentId_1_IncidentNumber_1_unique",
116
+ unique: true,
117
+ });
118
+
119
+ return mongoose.model<IncidentFilter>("IncidentFilter", modelSchema, "massive_incident_filter", { overwriteModels: true });
120
+ }
121
+
122
+ export interface IncidentFilterModel extends Model<IncidentFilter> { }
@@ -98,17 +98,5 @@ describe("Department", function() {
98
98
  const callerResolver = sut.callerLocation.resolvers.find(() => true);
99
99
  assert.isObject(callerResolver);
100
100
  assert.equal(callerResolver?.type, m.AccountCallerType.Dummy);
101
-
102
- const if1 = sut.incidentFilters.find(() => true);
103
- assert.isObject(if1);
104
- assert.equal(if1?.name, "Filter 1");
105
- assert.equal(if1?.position, 12);
106
- assert.equal(if1?.type, m.IncidentFilterType.AgencyId);
107
- const if1o1 = if1?.options.find(() => true);
108
- assert.equal(if1o1?.name, "Opt 1");
109
- assert.equal(if1o1?.position, 10);
110
- assert.equal(if1o1?.area?.type, "Polygon");
111
- assert.equal(if1o1?.area?.coordinates.length, 1);
112
- assert.equal(if1o1?.value, "P1");
113
101
  });
114
102
  });
@@ -0,0 +1,41 @@
1
+ import { assert } from "chai";
2
+ import "mocha";
3
+ import * as m from "../index";
4
+ import { url } from "./config";
5
+ import mockModule from "./mock";
6
+
7
+ describe("IncidentFilter", function() {
8
+ let models: m.BackendModels, mongoose: m.MongooseModule;
9
+ let testItem: Partial<m.IncidentFilter>;
10
+ beforeEach(async function() {
11
+ const c = await m.connect(url);
12
+ models = c.models;
13
+ mongoose = c.mongoose;
14
+ const mock = mockModule({
15
+ mongoose
16
+ });
17
+ testItem = mock.incidentFilterAgency;
18
+ });
19
+
20
+ afterEach(async function() {
21
+ await mongoose.disconnect();
22
+ });
23
+
24
+ it("is saved", async function() {
25
+ assert.isObject(testItem);
26
+ const item = new models.IncidentFilter(testItem);
27
+ const sut = await item.save();
28
+
29
+ assert.equal(sut.name, testItem.name);
30
+ assert.equal(sut.position, testItem.position);
31
+ assert.equal(sut.kind, m.IncidentFilterKind.AgencyId);
32
+ assert.equal(sut.departmentId, testItem.departmentId);
33
+
34
+ const if1o1 = sut.options.find(() => true);
35
+ assert.equal(if1o1?.name, "Opt 1");
36
+ assert.equal(if1o1?.position, 10);
37
+ assert.equal(if1o1?.area?.type, "Polygon");
38
+ assert.equal(if1o1?.area?.coordinates.length, 1);
39
+ assert.equal(if1o1?.value, "P1");
40
+ });
41
+ });
package/src/test/mock.ts CHANGED
@@ -4,12 +4,13 @@ import * as uuid from "uuid";
4
4
  import { retrieveCurrentUnixTime } from "../helpers";
5
5
  import {
6
6
  AccountCallerType,
7
- IncidentFilterType,
7
+ IncidentFilterKind,
8
8
  ShareIncidentRuleKind,
9
9
  } from "../constants";
10
10
 
11
11
  import { CADIncident } from "../models/cad-incident";
12
12
  import { Department } from "../models/department";
13
+ import { IncidentFilter } from "models/incident-filter";
13
14
  import { ManagedIncident } from "../models/managed-incident";
14
15
 
15
16
  export default function mockModule(dependencies: { mongoose: Mongoose; }) {
@@ -689,25 +690,6 @@ export default function mockModule(dependencies: { mongoose: Mongoose; }) {
689
690
  new mongoose.Types.ObjectId(agency._id)
690
691
  ],
691
692
  signupKey: "A1B2",
692
- incidentFilters: [
693
- {
694
- name: "Filter 1",
695
- position: 12,
696
- options: [
697
- {
698
- name: "Opt 1",
699
- visible: false,
700
- position: 10,
701
- area: {
702
- type: "Polygon",
703
- coordinates: [[[0, 1], [1, 2], [2, 0]]],
704
- },
705
- value: "P1"
706
- }
707
- ],
708
- type: IncidentFilterType.AgencyId,
709
- }
710
- ],
711
693
  incidentTypes: [{
712
694
  name: "Type",
713
695
  value: "type",
@@ -962,6 +944,25 @@ export default function mockModule(dependencies: { mongoose: Mongoose; }) {
962
944
  uuid: "ABCDEF"
963
945
  };
964
946
 
947
+ const incidentFilterAgency: Partial<IncidentFilter> = {
948
+ departmentId,
949
+ name: "Filter 1",
950
+ position: 12,
951
+ options: [
952
+ {
953
+ name: "Opt 1",
954
+ visible: false,
955
+ position: 10,
956
+ area: {
957
+ type: "Polygon",
958
+ coordinates: [[[0, 1], [1, 2], [2, 0]]],
959
+ },
960
+ value: "P1"
961
+ }
962
+ ],
963
+ kind: IncidentFilterKind.AgencyId,
964
+ };
965
+
965
966
  const incidentTakeover = {
966
967
  _id: new mongoose.Types.ObjectId(),
967
968
  incident_id: "i1234",
@@ -1456,6 +1457,7 @@ export default function mockModule(dependencies: { mongoose: Mongoose; }) {
1456
1457
  esri,
1457
1458
  gstMapping,
1458
1459
  incidentEvent,
1460
+ incidentFilterAgency,
1459
1461
  incidentNotified,
1460
1462
  incidentTakeover,
1461
1463
  jobLog,
@@ -5,10 +5,8 @@ import { PubNubTokenSchemaType } from "./pubnub-token";
5
5
  import {
6
6
  AccountCallerType,
7
7
  AccountIndustry,
8
- IncidentFilterType,
9
8
  } from "../constants";
10
9
  import { ReportNumberSchemaType } from "./common-incident";
11
- import { GeoPolygon } from "./common";
12
10
 
13
11
  export interface WebhookProcessLocationConfigType {
14
12
  enabled: boolean,
@@ -424,21 +422,6 @@ export type AccountConfigurationCallerLocation = {
424
422
  resolvers: AccountConfigurationCallerLocationResolver[]
425
423
  };
426
424
 
427
- export type IncidentFilterOption = {
428
- name: string,
429
- visible: boolean,
430
- position: number,
431
- area: GeoPolygon,
432
- value: string,
433
- };
434
-
435
- export type IncidentFilter = {
436
- name: string,
437
- position: number,
438
- options: IncidentFilterOption[],
439
- type: IncidentFilterType,
440
- };
441
-
442
425
  export interface DepartmentType {
443
426
  _id: Types.ObjectId,
444
427
  id?: string,
@@ -482,7 +465,6 @@ export interface DepartmentType {
482
465
  firstArrivingEnabled: boolean,
483
466
  forwarding: ForwardingConfigType,
484
467
  gst: GSTConfigType,
485
- incidentFilters: IncidentFilter[],
486
468
  incidentReplay: IncidentReplayType,
487
469
  incidentTypes: IncidentTypeType[],
488
470
  incidentVehicleStatus: IncidentVehicleStatusConfigType,
@@ -0,0 +1,25 @@
1
+ import { Types } from "mongoose";
2
+ import {
3
+ IncidentFilterKind,
4
+ } from "../constants";
5
+ import { GeoPolygon } from "./common";
6
+
7
+ export type IncidentFilterOption = {
8
+ name: string,
9
+ visible: boolean,
10
+ position: number,
11
+ area: GeoPolygon,
12
+ value: string,
13
+ };
14
+
15
+ export interface IncidentFilterType {
16
+ _id: Types.ObjectId,
17
+ departmentId: string,
18
+ createdAt: Date,
19
+ updatedAt: Date,
20
+
21
+ name: string,
22
+ position: number,
23
+ kind: IncidentFilterKind,
24
+ options: IncidentFilterOption[],
25
+ }