@bluedot-innovation/models 2.0.7-alpha.2 → 2.0.7-alpha.4
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 +14 -5
- 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,
|
|
@@ -18,10 +18,19 @@ CalendarDateRangeFilterSchema.add({
|
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
function validateDateRange (endDate) {
|
|
21
|
-
let startDate =
|
|
22
|
-
endDate = new Date(endDate)
|
|
21
|
+
let startDate = this.startDate
|
|
23
22
|
|
|
24
|
-
if (
|
|
23
|
+
if (this.startDate) {
|
|
24
|
+
startDate = new Date(this.startDate)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (endDate) {
|
|
28
|
+
endDate = new Date(endDate)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (endDate && endDate < (new Date())) {
|
|
32
|
+
throw new Error('endDate cannot be less than current date. ')
|
|
33
|
+
} else if (startDate && endDate && endDate < startDate) {
|
|
25
34
|
throw new Error('startDate has to be less than endDate. ')
|
|
26
35
|
}
|
|
27
36
|
}
|