tabletcommand-backend-models 7.0.14 → 7.0.15

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 (61) hide show
  1. package/build/constants.js +36 -1
  2. package/build/constants.js.map +1 -1
  3. package/build/models/cad-incident-stream.js +2 -2
  4. package/build/models/cad-incident-stream.js.map +1 -1
  5. package/build/models/chart-device-stats.js +2 -2
  6. package/build/models/chart-device-stats.js.map +1 -1
  7. package/build/models/chart-incident.js +2 -2
  8. package/build/models/chart-incident.js.map +1 -1
  9. package/build/models/chart-managed-incident.js +2 -2
  10. package/build/models/chart-managed-incident.js.map +1 -1
  11. package/build/models/chart-user.js +2 -2
  12. package/build/models/chart-user.js.map +1 -1
  13. package/build/models/department.js +2 -2
  14. package/build/models/department.js.map +1 -1
  15. package/build/models/incident-event.js +2 -2
  16. package/build/models/incident-event.js.map +1 -1
  17. package/build/models/job-log.js +2 -2
  18. package/build/models/job-log.js.map +1 -1
  19. package/build/models/location.js +37 -2
  20. package/build/models/location.js.map +1 -1
  21. package/build/models/managed-incident.js +2 -2
  22. package/build/models/managed-incident.js.map +1 -1
  23. package/build/models/monitor.js +2 -2
  24. package/build/models/monitor.js.map +1 -1
  25. package/build/models/schema/cad-incident.js +2 -3
  26. package/build/models/schema/cad-incident.js.map +1 -1
  27. package/build/models/smtp-unhandled.js +2 -2
  28. package/build/models/smtp-unhandled.js.map +1 -1
  29. package/build/test/location.js +12 -1
  30. package/build/test/location.js.map +1 -1
  31. package/build/test/mock.js +10 -1
  32. package/build/test/mock.js.map +1 -1
  33. package/definitions/constants.d.ts +6 -0
  34. package/definitions/constants.d.ts.map +1 -1
  35. package/definitions/models/location.d.ts +2 -0
  36. package/definitions/models/location.d.ts.map +1 -1
  37. package/definitions/models/schema/cad-incident.d.ts.map +1 -1
  38. package/definitions/test/mock.d.ts +1 -0
  39. package/definitions/test/mock.d.ts.map +1 -1
  40. package/definitions/types/location.d.ts +24 -23
  41. package/definitions/types/location.d.ts.map +1 -1
  42. package/package.json +6 -6
  43. package/src/constants.ts +36 -0
  44. package/src/models/cad-incident-stream.ts +1 -1
  45. package/src/models/chart-device-stats.ts +1 -1
  46. package/src/models/chart-incident.ts +1 -1
  47. package/src/models/chart-managed-incident.ts +1 -1
  48. package/src/models/chart-user.ts +1 -1
  49. package/src/models/department.ts +1 -1
  50. package/src/models/incident-event.ts +1 -1
  51. package/src/models/job-log.ts +1 -1
  52. package/src/models/location.ts +41 -2
  53. package/src/models/managed-incident.ts +1 -1
  54. package/src/models/monitor.ts +1 -1
  55. package/src/models/schema/cad-incident.ts +1 -3
  56. package/src/models/smtp-unhandled.ts +1 -1
  57. package/src/mongoose-lean-virtuals.d.ts +4 -2
  58. package/src/test/location.ts +15 -1
  59. package/src/test/mock.ts +10 -1
  60. package/src/tsconfig.json +5 -12
  61. package/src/types/location.ts +22 -24
@@ -1,14 +1,17 @@
1
1
  import * as uuid from "uuid";
2
+ import { isArray, isString } from "lodash";
3
+
2
4
  import {
3
5
  currentDate,
4
6
  MongooseDocument,
5
7
  MongooseModule,
6
8
  } from "../helpers";
7
- import * as mongooseLeanVirtuals from "mongoose-lean-virtuals";
9
+ import mongooseLeanVirtuals from "mongoose-lean-virtuals";
8
10
  import ColorModule from "./schema/color";
9
11
  import GeoJSONPointModule from "./schema/geojson-point";
10
12
  import { Model } from "mongoose";
11
13
  import { LocationType } from "../types/location";
14
+ import { LocationVisibility } from "../constants";
12
15
 
13
16
  export interface Location extends LocationType, Record<string, unknown> { }
14
17
 
@@ -172,6 +175,12 @@ export default async function LocationModule(mongoose: MongooseModule) {
172
175
  type: Date,
173
176
  default: currentDate,
174
177
  },
178
+
179
+ // combines .sendToCAD, .active, .shared as LocationVisibility[]
180
+ visibility: {
181
+ type: [String],
182
+ default: [],
183
+ },
175
184
  }, {
176
185
  });
177
186
 
@@ -215,4 +224,34 @@ export default async function LocationModule(mongoose: MongooseModule) {
215
224
  return mongoose.model<Location>("Location", modelSchema, "massive_location", { overwriteModels: true });
216
225
  }
217
226
 
218
- export interface LocationModel extends Model<Location> { }
227
+ export interface LocationModel extends Model<Location> { }
228
+
229
+ export function decodeLocationVisibility(str: unknown): LocationVisibility[] {
230
+ const out: LocationVisibility[] = [];
231
+ if (!isArray(str)) {
232
+ return out;
233
+ }
234
+
235
+ str.forEach((elem: unknown) => {
236
+ if (!isString(elem)) {
237
+ return;
238
+ }
239
+
240
+ switch (elem.toLowerCase()) {
241
+ case LocationVisibility.Hidden.toLowerCase():
242
+ out.push(LocationVisibility.Hidden);
243
+ break;
244
+ case LocationVisibility.Visible.toLowerCase():
245
+ out.push(LocationVisibility.Visible);
246
+ break;
247
+ case LocationVisibility.CAD.toLowerCase():
248
+ out.push(LocationVisibility.CAD);
249
+ break;
250
+ case LocationVisibility.Shared.toLowerCase():
251
+ out.push(LocationVisibility.Shared);
252
+ break;
253
+ }
254
+ });
255
+
256
+ return out;
257
+ }
@@ -1,4 +1,4 @@
1
- import * as mongooseLeanVirtuals from "mongoose-lean-virtuals";
1
+ import mongooseLeanVirtuals from "mongoose-lean-virtuals";
2
2
  import * as uuid from "uuid";
3
3
  import {
4
4
  currentDate,
@@ -4,7 +4,7 @@ import {
4
4
  MongooseModule,
5
5
  retrieveCurrentUnixTime,
6
6
  } from "../helpers";
7
- import * as mongooseLeanVirtuals from "mongoose-lean-virtuals";
7
+ import mongooseLeanVirtuals from "mongoose-lean-virtuals";
8
8
  import { MonitorType } from "../types/monitor";
9
9
 
10
10
  export interface Monitor extends MonitorType { }
@@ -1,12 +1,10 @@
1
- //x-disabled <reference types="../../mongoose-lean-virtuals" />
2
-
3
1
  import {
4
2
  currentDate,
5
3
  MongooseModule,
6
4
  } from "../../helpers";
7
5
 
8
6
  import * as uuid from "uuid";
9
- import * as mongooseLeanVirtuals from "mongoose-lean-virtuals";
7
+ import mongooseLeanVirtuals from "mongoose-lean-virtuals";
10
8
  import { IncidentEventSchema } from "../incident-event";
11
9
  import {
12
10
  CADPersonSchema,
@@ -3,7 +3,7 @@ import {
3
3
  MongooseDocument,
4
4
  MongooseModule,
5
5
  } from "../helpers";
6
- import * as mongooseLeanVirtuals from "mongoose-lean-virtuals";
6
+ import mongooseLeanVirtuals from "mongoose-lean-virtuals";
7
7
  import { SMTPUnhandledType } from "../types/smtp-unhandled";
8
8
 
9
9
  export interface SMTPUnhandled extends SMTPUnhandledType { }
@@ -1,4 +1,6 @@
1
1
  declare module "mongoose-lean-virtuals" {
2
- const mongooseLeanVirtuals: (schema: import("mongoose").Schema) => import("mongoose").Schema;
3
- export = mongooseLeanVirtuals;
2
+ import { Schema } from "mongoose";
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ const mongooseLeanVirtuals: <T>(schema: Schema<T>, opts?: any) => void;
5
+ export default mongooseLeanVirtuals;
4
6
  }
@@ -3,6 +3,8 @@ import "mocha";
3
3
  import * as m from "../index";
4
4
  import * as config from "./config";
5
5
  import mockModule from "./mock";
6
+ import { decodeLocationVisibility } from "../models/location";
7
+ import { LocationVisibility } from "../constants";
6
8
 
7
9
  describe("Location", function() {
8
10
  let models: m.BackendModels, mongoose: m.MongooseModule;
@@ -24,7 +26,6 @@ describe("Location", function() {
24
26
  it("is saved", async function() {
25
27
  const item = new models.Location(testItem);
26
28
  const sut = await item.save();
27
- await models.Location.findOne({ _id: testItem._id });
28
29
  assert.isNotNull(testItem._id);
29
30
  assert.equal(testItem.departmentId, sut.departmentId);
30
31
  assert.equal(testItem.userId, sut.userId);
@@ -76,4 +77,17 @@ describe("Location", function() {
76
77
 
77
78
  await models.Location.collection.dropIndexes();
78
79
  });
80
+
81
+ it("decodes .visibility", async function() {
82
+ const item = new models.Location(testItem);
83
+ const sut = await item.save();
84
+
85
+ const sutVis = decodeLocationVisibility(sut.visibility);
86
+
87
+ assert.equal(sutVis.length, 4);
88
+ assert.notEqual(sutVis.indexOf(LocationVisibility.Hidden), -1);
89
+ assert.notEqual(sutVis.indexOf(LocationVisibility.Visible), -1);
90
+ assert.notEqual(sutVis.indexOf(LocationVisibility.CAD), -1);
91
+ assert.notEqual(sutVis.indexOf(LocationVisibility.Shared), -1);
92
+ });
79
93
  });
package/src/test/mock.ts CHANGED
@@ -956,7 +956,16 @@ export default function mockModule(dependencies: { mongoose: Mongoose; }) {
956
956
  text: "#00AA00",
957
957
  background: "#FFAAFF"
958
958
  },
959
- modified: new Date()
959
+ modified: new Date(),
960
+ visibility: [
961
+ "hidden",
962
+ "visible",
963
+ "cad",
964
+ "shared",
965
+ // Does not exist
966
+ "none",
967
+ "",
968
+ ]
960
969
  };
961
970
 
962
971
  const managedIncident = {
package/src/tsconfig.json CHANGED
@@ -13,19 +13,12 @@
13
13
  "noUncheckedIndexedAccess": true,
14
14
  "noUnusedLocals": true,
15
15
  "outDir": "../build",
16
- "paths": {
17
- "*": [
18
- "../node_modules/@types/*",
19
- "*"
20
- ]
21
- },
22
16
  "resolveJsonModule": true,
23
17
  "sourceMap": true,
24
18
  "strict": true,
25
19
  "target": "es2017",
26
- "types": [
27
- "node",
28
- "mocha"
29
- ]
30
- }
31
- }
20
+ "types": ["node", "mocha"]
21
+ },
22
+ "include": ["**/*.ts", "mongoose-lean-virtuals.d.ts"],
23
+ "exclude": ["node_modules"],
24
+ }
@@ -5,37 +5,35 @@ import { ColorSchemaType } from "./color";
5
5
  export interface LocationType {
6
6
  _id: Types.ObjectId,
7
7
  id?: string,
8
- departmentId: string,
9
- userId: string,
10
- uuid: string,
11
- username: string,
12
- device_type: string,
13
8
  active: boolean,
14
- deleteAfterDate: Date,
15
- modified: Date,
16
- movedAt: Date,
17
- propsChangedAt: Date,
18
- version: number,
19
- session: string,
9
+ agencyCode: string,
10
+ agencyName: string,
20
11
  altitude: number,
21
- heading: number,
22
- speed: number,
12
+ color: ColorSchemaType,
13
+ colorChangedAt: Date,
14
+ deleteAfterDate: Date,
15
+ departmentId: string,
16
+ device_type: string,
23
17
  esriId: number,
18
+ heading: number,
19
+ kindType: string,
20
+ location?: { latitude: number, longitude: number, }; // provided by virtual.location
24
21
  locationGeoJSON: GeoJSONPointType,
22
+ modified: Date,
23
+ movedAt: Date,
25
24
  opAreaCode: string
26
25
  opAreaName: string,
27
- agencyCode: string,
28
- agencyName: string,
29
- shared: boolean,
30
- state: string,
26
+ propsChangedAt: Date,
31
27
  sendToCAD: boolean,
32
- color: ColorSchemaType,
33
- colorChangedAt: Date,
28
+ session: string,
29
+ shared: boolean,
34
30
  source: string,
35
- kindType: string,
31
+ speed: number,
32
+ state: string,
36
33
  typeDetails: object
37
- location?: {
38
- latitude: number,
39
- longitude: number,
40
- };
34
+ userId: string,
35
+ username: string,
36
+ uuid: string,
37
+ version: number,
38
+ visibility: string[],
41
39
  }