salix/modules/zone/back/models/zone-event.js

38 lines
975 B
JavaScript
Raw Normal View History

2020-01-22 09:41:09 +00:00
const app = require('vn-loopback/server/server');
2019-09-25 18:06:42 +00:00
module.exports = Self => {
2019-11-18 15:31:37 +00:00
Self.validate('range', function(err) {
if (this.type == 'range'
&& !this.started
&& !this.ended)
2019-09-25 18:06:42 +00:00
err();
2019-11-18 15:31:37 +00:00
}, {
message: `You should specify at least a start or end date`
});
Self.validate('validRange', function(err) {
if (this.type == 'range'
&& this.started
&& this.ended
&& this.started >= this.ended)
err();
}, {
2019-09-25 18:06:42 +00:00
message: `Start date should be lower than end date`
});
2019-11-18 15:31:37 +00:00
Self.validate('dated', function(err) {
if (this.type == 'day' && !this.dated)
err();
}, {
message: `You should specify a date`
});
Self.validate('weekDays', function(err) {
if (['range', 'indefinitely'].indexOf(this.type) !== -1
&& !this.weekDays)
err();
}, {
message: `You should mark at least one week day`
});
2019-09-25 18:06:42 +00:00
};