@bluedot-innovation/models 2.0.14 → 2.0.16-alpha.1
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/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
## 2.0.16
|
|
2
|
+
- Don't enforce in `CalendarDateRangeFilter` that `endDate` is later than current date.
|
|
3
|
+
|
|
4
|
+
## 2.0.15
|
|
5
|
+
- Update `bearingFilter` with new business logic.
|
|
6
|
+
|
|
1
7
|
## 2.0.14
|
|
2
|
-
-
|
|
8
|
+
- Remove `password` from user model
|
|
3
9
|
|
|
4
10
|
## 2.0.13
|
|
5
11
|
- Republish to bring changes from 2.0.11
|
|
6
12
|
|
|
7
13
|
## 2.0.12
|
|
8
|
-
- Update bearingFilter to allow wrap around angles (e.g. 315deg & 45deg)
|
|
14
|
+
- Update `bearingFilter` to allow wrap around angles (e.g. 315deg & 45deg)
|
|
9
15
|
|
|
10
16
|
## 2.0.11
|
|
11
17
|
- Added uuid as `_id` for user
|
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
mongoose.Promise = global.Promise
|
|
3
3
|
|
|
4
4
|
const BearingFilterModel = require('../../../Models').BearingFilter(mongoose)
|
|
5
|
-
const {
|
|
5
|
+
const { isMinimumNinetyApart } = require.main.require('models/BearingFilter')
|
|
6
6
|
const describe = require('mocha').describe
|
|
7
7
|
const it = require('mocha').it
|
|
8
8
|
const chai = require('chai')
|
|
@@ -92,34 +92,41 @@ describe('BearingFilter', () => {
|
|
|
92
92
|
})
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
-
describe('
|
|
96
|
-
|
|
95
|
+
describe.only('isMinimumNinetyApart(fromAngle, toAngle)', () => {
|
|
96
|
+
describe('should return true if the angles are at least 90 degrees apart in both directions', () => {
|
|
97
97
|
const angles = [
|
|
98
|
+
[360, 90],
|
|
99
|
+
[0, 90],
|
|
98
100
|
[90, 180],
|
|
99
101
|
[50, 140],
|
|
100
|
-
[315,
|
|
102
|
+
[315, 50],
|
|
101
103
|
[300, 30],
|
|
102
104
|
[211, 301]
|
|
103
105
|
]
|
|
104
106
|
|
|
105
107
|
angles.forEach(([fromAngle, toAngle]) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
it(`fromAngle ${fromAngle} and toAngle ${toAngle} should be true`, () => {
|
|
109
|
+
const result = isMinimumNinetyApart(fromAngle, toAngle)
|
|
110
|
+
assert.isTrue(result)
|
|
111
|
+
})
|
|
108
112
|
})
|
|
109
113
|
})
|
|
110
114
|
|
|
111
|
-
|
|
115
|
+
describe('should return false if the angles are NOT at least 90 degrees apart in both directions', () => {
|
|
112
116
|
const angles = [
|
|
113
|
-
[
|
|
117
|
+
[359, 2],
|
|
114
118
|
[50, 90],
|
|
115
119
|
[315, 360],
|
|
116
120
|
[180, 181],
|
|
117
|
-
[
|
|
121
|
+
[0, 89],
|
|
122
|
+
[360, 89]
|
|
118
123
|
]
|
|
119
124
|
|
|
120
125
|
angles.forEach(([fromAngle, toAngle]) => {
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
it(`fromAngle ${fromAngle} and toAngle ${toAngle} should be false`, () => {
|
|
127
|
+
const result = isMinimumNinetyApart(fromAngle, toAngle)
|
|
128
|
+
assert.isFalse(result)
|
|
129
|
+
})
|
|
123
130
|
})
|
|
124
131
|
})
|
|
125
132
|
})
|
package/models/BearingFilter.js
CHANGED
|
@@ -27,28 +27,36 @@ function validateAngles (toAngle, magicCallback) {
|
|
|
27
27
|
return magicCallback(false, 'fromAngle is required')
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
if (toAngle
|
|
31
|
-
return magicCallback(false, '
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!isNinetyApart(fromAngle, toAngle)) {
|
|
35
|
-
return magicCallback(false, 'From Angle and To Angle must be separated by 90 degrees in either direction')
|
|
30
|
+
if (!isMinimumNinetyApart(fromAngle, toAngle)) {
|
|
31
|
+
return magicCallback(false, 'From Angle and To Angle must be separated by at least 90 degrees in either direction')
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
magicCallback(true)
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
function
|
|
37
|
+
function isMinimumNinetyApart (fromAngle, toAngle) {
|
|
42
38
|
const fromAngleWrapped = parseInt(fromAngle) + 360
|
|
43
39
|
const toAngleWrapped = parseInt(toAngle) + 360
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
40
|
+
const lessThan90 = Math.abs(fromAngle - toAngle) < 90
|
|
41
|
+
const fromAngleLarger = fromAngle > toAngle
|
|
42
|
+
const lessThan90Wrapped = fromAngleLarger
|
|
43
|
+
? (toAngleWrapped - fromAngle) < 90
|
|
44
|
+
: (fromAngleWrapped - toAngle) < 90
|
|
45
|
+
|
|
46
|
+
if (lessThan90 || lessThan90Wrapped) { return false }
|
|
47
|
+
return true
|
|
51
48
|
}
|
|
49
|
+
// function isMinimumNinetyApart (fromAngle, toAngle) {
|
|
50
|
+
// const fromAngleWrapped = parseInt(fromAngle) + 360
|
|
51
|
+
// const toAngleWrapped = parseInt(toAngle) + 360
|
|
52
|
+
// if ((fromAngle - toAngle) === 90 || (toAngle - fromAngle) === 90) {
|
|
53
|
+
// return true
|
|
54
|
+
// } else if (fromAngle > toAngle) {
|
|
55
|
+
// return (toAngleWrapped - fromAngle) === 90
|
|
56
|
+
// } else if (fromAngle < toAngle) {
|
|
57
|
+
// return (fromAngleWrapped - toAngle) === 90
|
|
58
|
+
// }
|
|
59
|
+
// }
|
|
52
60
|
|
|
53
61
|
// optional mongoose
|
|
54
62
|
let model = (mongooseInstance) => {
|
|
@@ -66,5 +74,5 @@ module.exports = {
|
|
|
66
74
|
Model: model,
|
|
67
75
|
Schema: BearingFilterSchema,
|
|
68
76
|
bearingFilterSchema: schema,
|
|
69
|
-
|
|
77
|
+
isMinimumNinetyApart
|
|
70
78
|
}
|
|
@@ -28,9 +28,7 @@ function validateDateRange (endDate, magicCallback) {
|
|
|
28
28
|
endDate = new Date(endDate)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
if (endDate && endDate <
|
|
32
|
-
return magicCallback(false, `endDate cannot be less than current date.`)
|
|
33
|
-
} else if (startDate && endDate && endDate < startDate) {
|
|
31
|
+
if (startDate && endDate && endDate < startDate) {
|
|
34
32
|
return magicCallback(false, `startDate has to be less than endDate.`)
|
|
35
33
|
}
|
|
36
34
|
magicCallback(true)
|