@bluedot-innovation/models 2.0.7-alpha.3 → 2.0.7-alpha.5
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/__tests__/filter/calendarDateRange/calendarDateRangeFilter.data.json +1 -1
- package/__tests__/filter/calendarDateRange/calendarDateRangeFilter.rules.json +1 -1
- package/__tests__/zone/zone.data.json +1 -1
- package/__tests__/zone/zone.filter.spec.js +1 -1
- package/__tests__/zone/zone.spec.js +1 -1
- package/models/CalendarDateRangeFilter.js +17 -7
- package/models/MessageAction.js +0 -1
- package/package.json +1 -1
|
@@ -36,7 +36,7 @@ testCase('Zone - Filter', () => {
|
|
|
36
36
|
|
|
37
37
|
testCase('Invalid Zone - Filter', () => {
|
|
38
38
|
assertions('should throw an error when an invalid filter is instantiated within a zone', (done) => {
|
|
39
|
-
|
|
39
|
+
zone.filters[0].startDate = 'abc'
|
|
40
40
|
let Zone = new ZoneModel(zone)
|
|
41
41
|
Zone.validate((err, res) => {
|
|
42
42
|
assert.exists(err, 'err object should exist')
|
|
@@ -94,7 +94,7 @@ testCase('Zone', () => {
|
|
|
94
94
|
})
|
|
95
95
|
})
|
|
96
96
|
assertions('should throw an error when a filter is invalid', (done) => {
|
|
97
|
-
|
|
97
|
+
zone.filters[0].startDate = 'abc'
|
|
98
98
|
let Zone = new ZoneModel(zone)
|
|
99
99
|
Zone.validate((err, res) => {
|
|
100
100
|
assert.exists(err, 'err object should exist')
|
|
@@ -3,8 +3,8 @@ let uuidv4 = require('uuid/v4')
|
|
|
3
3
|
|
|
4
4
|
let schema = {
|
|
5
5
|
_id: {type: String, default: uuidv4},
|
|
6
|
-
startDate: {type: Date
|
|
7
|
-
endDate: {type: Date,
|
|
6
|
+
startDate: {type: Date},
|
|
7
|
+
endDate: {type: Date, validate: validateDateRange}
|
|
8
8
|
}
|
|
9
9
|
let CalendarDateRangeFilterSchema = new mongoose.Schema(
|
|
10
10
|
schema,
|
|
@@ -17,13 +17,23 @@ CalendarDateRangeFilterSchema.add({
|
|
|
17
17
|
{type: String, required: true}
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
function validateDateRange (endDate) {
|
|
21
|
-
let startDate =
|
|
22
|
-
endDate = new Date(endDate)
|
|
20
|
+
function validateDateRange (endDate, magicCallback) {
|
|
21
|
+
let startDate = this.startDate
|
|
23
22
|
|
|
24
|
-
if (
|
|
25
|
-
|
|
23
|
+
if (this.startDate) {
|
|
24
|
+
startDate = new Date(this.startDate)
|
|
26
25
|
}
|
|
26
|
+
|
|
27
|
+
if (endDate) {
|
|
28
|
+
endDate = new Date(endDate)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (endDate && endDate < (new Date())) {
|
|
32
|
+
return magicCallback(false, `endDate cannot be less than current date.`)
|
|
33
|
+
} else if (startDate && endDate && endDate < startDate) {
|
|
34
|
+
return magicCallback(false, `startDate has to be less than endDate. `)
|
|
35
|
+
}
|
|
36
|
+
magicCallback(true)
|
|
27
37
|
}
|
|
28
38
|
|
|
29
39
|
// optional mongoose
|
package/models/MessageAction.js
CHANGED