salix/modules/route/back/models/route.js

26 lines
777 B
JavaScript

module.exports = Self => {
require('../methods/route/filter')(Self);
require('../methods/route/summary')(Self);
require('../methods/route/getTickets')(Self);
require('../methods/route/guessPriority')(Self);
require('../methods/route/updateVolume')(Self);
require('../methods/route/getDeliveryPoint')(Self);
Self.validate('kmStart', validateDistance, {
message: 'Distance must be lesser than 1000'
});
Self.validate('kmEnd', validateDistance, {
message: 'Distance must be lesser than 1000'
});
function validateDistance(err) {
const routeTotalKm = this.kmEnd - this.kmStart;
const routeMaxKm = 1000;
if ( routeTotalKm > routeMaxKm || this.kmStart > this.kmEnd)
err();
}
};