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

46 lines
1.2 KiB
JavaScript

const app = require('vn-loopback/server/server');
module.exports = Self => {
Self.validate('range', function(err) {
if (this.type == 'range'
&& !this.started
&& !this.ended)
err();
}, {
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();
}, {
message: `Start date should be lower than end date`
});
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`
});
Self.observe('after save', async function() {
await app.models.ZoneClosure.doRecalc();
});
Self.observe('after delete', async function() {
await app.models.ZoneClosure.doRecalc();
});
};