tabletcommand-backend-models 5.15.4 → 5.16.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.
- package/build/models/location.js +11 -12
- package/build/models/location.js.map +1 -1
- package/definitions/models/location.d.ts +0 -4
- package/definitions/models/location.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/models/location.ts +12 -12
- package/test/department.js +1 -0
- package/test/location.js +5 -4
- package/test/mock.js +1 -5
package/build/models/location.js
CHANGED
|
@@ -84,18 +84,6 @@ async function LocationModule(mongoose) {
|
|
|
84
84
|
type: Number,
|
|
85
85
|
default: 0,
|
|
86
86
|
},
|
|
87
|
-
location: {
|
|
88
|
-
longitude: {
|
|
89
|
-
type: Number,
|
|
90
|
-
required: true,
|
|
91
|
-
default: 0,
|
|
92
|
-
},
|
|
93
|
-
latitude: {
|
|
94
|
-
type: Number,
|
|
95
|
-
required: true,
|
|
96
|
-
default: 0,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
87
|
// Shared AVL
|
|
100
88
|
locationGeoJSON: {
|
|
101
89
|
type: GeoJSONPoint,
|
|
@@ -139,6 +127,17 @@ async function LocationModule(mongoose) {
|
|
|
139
127
|
modelSchema.virtual("id").get(function () {
|
|
140
128
|
return this._id.toHexString();
|
|
141
129
|
});
|
|
130
|
+
modelSchema.virtual("location").get(function () {
|
|
131
|
+
const location = {
|
|
132
|
+
latitude: 0,
|
|
133
|
+
longitude: 0
|
|
134
|
+
};
|
|
135
|
+
if (this && this.locationGeoJSON && this.locationGeoJSON.coordinates && this.locationGeoJSON.coordinates.length === 2) {
|
|
136
|
+
location.longitude = this.locationGeoJSON.coordinates[0];
|
|
137
|
+
location.latitude = this.locationGeoJSON.coordinates[1];
|
|
138
|
+
}
|
|
139
|
+
return location;
|
|
140
|
+
});
|
|
142
141
|
// Create GeoJSON index
|
|
143
142
|
modelSchema.index({
|
|
144
143
|
locationGeoJSON: "2dsphere",
|
|
@@ -1 +1 @@
|
|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CAAC;QAChB,eAAe,EAAE,UAAU;QAC3B,MAAM,EAAE,CAAC;QACT,YAAY,EAAE,CAAC;QACf,kBAAkB,EAAE,CAAC;KACtB,CAAC,CAAC;IACH,WAAW,CAAC,KAAK,CAAC;QAChB,eAAe,EAAE,UAAU;QAC3B,MAAM,EAAE,CAAC;QACT,YAAY,EAAE,CAAC;QACf,QAAQ,EAAE,CAAC;KACZ,CAAC,CAAC;IACH,WAAW,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACzC,WAAW,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,IAAA,qBAAW,EAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AACxD,CAAC;AA7JD,wCA6JC;AAID,kBAAe,cAA8E,CAAC"}
|
|
@@ -17,10 +17,6 @@ export declare function LocationModule(mongoose: MongooseModule): Promise<import
|
|
|
17
17
|
heading: number;
|
|
18
18
|
speed: number;
|
|
19
19
|
esriId: number;
|
|
20
|
-
location: {
|
|
21
|
-
longitude: number;
|
|
22
|
-
latitude: number;
|
|
23
|
-
};
|
|
24
20
|
locationGeoJSON: import("../helpers").MongooseInterface<{
|
|
25
21
|
type: {
|
|
26
22
|
type: StringConstructor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../src/models/location.ts"],"names":[],"mappings":";AACA,OAAO,EAKL,8BAA8B,EAC9B,+BAA+B,EAE/B,cAAc,EACd,sBAAsB,EAEvB,MAAM,YAAY,CAAC;AAKpB,wBAAsB,cAAc,CAAC,QAAQ,EAAE,cAAc
|
|
1
|
+
{"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../src/models/location.ts"],"names":[],"mappings":";AACA,OAAO,EAKL,8BAA8B,EAC9B,+BAA+B,EAE/B,cAAc,EACd,sBAAsB,EAEvB,MAAM,YAAY,CAAC;AAKpB,wBAAsB,cAAc,CAAC,QAAQ,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6J5D;AAED,MAAM,WAAW,QAAS,SAAQ,8BAA8B,CAAC,OAAO,cAAc,CAAC;CAAI;AAC3F,MAAM,WAAW,aAAc,SAAQ,+BAA+B,CAAC,QAAQ,CAAC;CAAI;;AACpF,wBAA8F"}
|
package/package.json
CHANGED
package/src/models/location.ts
CHANGED
|
@@ -96,18 +96,6 @@ export async function LocationModule(mongoose: MongooseModule) {
|
|
|
96
96
|
default: 0,
|
|
97
97
|
},
|
|
98
98
|
|
|
99
|
-
location: {
|
|
100
|
-
longitude: {
|
|
101
|
-
type: Number,
|
|
102
|
-
required: true,
|
|
103
|
-
default: 0,
|
|
104
|
-
},
|
|
105
|
-
latitude: {
|
|
106
|
-
type: Number,
|
|
107
|
-
required: true,
|
|
108
|
-
default: 0,
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
99
|
// Shared AVL
|
|
112
100
|
locationGeoJSON: {
|
|
113
101
|
type: GeoJSONPoint,
|
|
@@ -156,6 +144,18 @@ export async function LocationModule(mongoose: MongooseModule) {
|
|
|
156
144
|
return this._id.toHexString();
|
|
157
145
|
});
|
|
158
146
|
|
|
147
|
+
modelSchema.virtual("location").get(function(this: { locationGeoJSON: { coordinates: number[] }} | null | undefined) {
|
|
148
|
+
const location = {
|
|
149
|
+
latitude: 0,
|
|
150
|
+
longitude: 0
|
|
151
|
+
};
|
|
152
|
+
if (this && this.locationGeoJSON && this.locationGeoJSON.coordinates && this.locationGeoJSON.coordinates.length === 2) {
|
|
153
|
+
location.longitude = this.locationGeoJSON.coordinates[0];
|
|
154
|
+
location.latitude = this.locationGeoJSON.coordinates[1];
|
|
155
|
+
}
|
|
156
|
+
return location;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
159
|
// Create GeoJSON index
|
|
160
160
|
modelSchema.index({
|
|
161
161
|
locationGeoJSON: "2dsphere",
|
package/test/department.js
CHANGED
|
@@ -26,6 +26,7 @@ describe("Department", function() {
|
|
|
26
26
|
assert.isObject(testItem);
|
|
27
27
|
const item = new models.Department(testItem);
|
|
28
28
|
const sut = await item.save();
|
|
29
|
+
const result = await models.Department.findOne({_id: testItem._id}).lean();
|
|
29
30
|
assert.isNotNull(sut._id);
|
|
30
31
|
assert.isNotNull(sut.id);
|
|
31
32
|
assert.equal(sut.department, testItem.department);
|
package/test/location.js
CHANGED
|
@@ -25,6 +25,7 @@ describe("Location", function() {
|
|
|
25
25
|
it("is saved", async function() {
|
|
26
26
|
const item = new models.Location(testItem);
|
|
27
27
|
const sut = await item.save();
|
|
28
|
+
const result = 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);
|
|
@@ -35,11 +36,11 @@ describe("Location", function() {
|
|
|
35
36
|
assert.equal(testItem.session, sut.session);
|
|
36
37
|
assert.equal(testItem.active, sut.active);
|
|
37
38
|
assert.equal(testItem.heading, sut.heading);
|
|
38
|
-
assert.equal(testItem.location.longitude, sut.location.longitude);
|
|
39
|
-
assert.equal(testItem.location.latitude, sut.location.latitude);
|
|
40
|
-
assert.equal(testItem.locationGeoJSON.type, "Point");
|
|
41
39
|
assert.equal(testItem.locationGeoJSON.coordinates[0], sut.location.longitude);
|
|
42
40
|
assert.equal(testItem.locationGeoJSON.coordinates[1], sut.location.latitude);
|
|
41
|
+
assert.equal(testItem.locationGeoJSON.type, "Point");
|
|
42
|
+
assert.equal(testItem.locationGeoJSON.coordinates[0], sut.locationGeoJSON.coordinates[0]);
|
|
43
|
+
assert.equal(testItem.locationGeoJSON.coordinates[1], sut.locationGeoJSON.coordinates[1]);
|
|
43
44
|
assert.equal(testItem.opAreaCode, sut.opAreaCode);
|
|
44
45
|
assert.equal(testItem.opAreaName, sut.opAreaName);
|
|
45
46
|
assert.equal(testItem.shared, sut.shared);
|
|
@@ -64,7 +65,7 @@ describe("Location", function() {
|
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
try {
|
|
67
|
-
await models.Location.findOne(geoQuery);
|
|
68
|
+
const result = await models.Location.findOne(geoQuery);
|
|
68
69
|
assert.isFalse(true, "Expecting above to fail.");
|
|
69
70
|
} catch (error) {
|
|
70
71
|
assert.isNotNull(error, "Expecting above to fail");
|
package/test/mock.js
CHANGED
|
@@ -593,13 +593,9 @@ module.exports = function(dependencies) {
|
|
|
593
593
|
device_type: "iPad",
|
|
594
594
|
active: true,
|
|
595
595
|
heading: 43,
|
|
596
|
-
location: {
|
|
597
|
-
longitude: -122.304,
|
|
598
|
-
latitude: 37.541
|
|
599
|
-
},
|
|
600
596
|
locationGeoJSON: {
|
|
601
597
|
type: "Point",
|
|
602
|
-
coordinates: [-
|
|
598
|
+
coordinates: [-120.001, 37.001],
|
|
603
599
|
},
|
|
604
600
|
session: "abcd",
|
|
605
601
|
opAreaCode: "DAL",
|