@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.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "type" : "calendarDateRange",
3
3
  "startDate" : "2017-11-14",
4
- "endDate" : "2017-11-15"
4
+ "endDate" : "2030-11-15"
5
5
  }
@@ -1,3 +1,3 @@
1
1
  {
2
- "requiredFields":["type", "startDate", "endDate"]
2
+ "requiredFields":["type"]
3
3
  }
@@ -26,7 +26,7 @@
26
26
  {
27
27
  "type" : "calendarDateRange",
28
28
  "startDate" : "2017-11-14",
29
- "endDate" : "2017-11-15"
29
+ "endDate" : "2030-11-15"
30
30
  }
31
31
  ],
32
32
  "geofeatures": [{
@@ -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
- delete zone.filters[0].startDate
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
- delete zone.filters[0].startDate
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, required: [true, 'startDate is required. ']},
7
- endDate: {type: Date, required: [true, 'endDate is required. '], validate: validateDateRange}
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 = new Date(this.startDate)
22
- endDate = new Date(endDate)
21
+ let startDate = this.startDate
23
22
 
24
- if (endDate < startDate) {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "2.0.7-alpha.2",
3
+ "version": "2.0.7-alpha.4",
4
4
  "description": "",
5
5
  "main": "Models.js",
6
6
  "scripts": {