backend modifications for route tickets
This commit is contained in:
parent
49216e09c9
commit
fb418edc7b
|
@ -2257,3 +2257,10 @@ INSERT INTO `vn`.`ticketRecalc`(`ticketFk`)
|
|||
SELECT `id` FROM `vn`.`ticket`;
|
||||
|
||||
CALL `vn`.`ticket_doRecalc`();
|
||||
|
||||
INSERT INTO `vn`.`zoneAgencyMode`(`id`, `agencyModeFk`, `zoneFk`)
|
||||
VALUES
|
||||
(1, 1, 1),
|
||||
(2, 1, 2),
|
||||
(3, 6, 5),
|
||||
(4, 7, 1);
|
|
@ -0,0 +1,44 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('getSuggestedTickets', {
|
||||
description: 'Returns an array of suggested tickets for the given route',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The route id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getSuggestedTickets`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getSuggestedTickets = async id => {
|
||||
const route = await Self.app.models.Route.findById(id);
|
||||
|
||||
const zoneAgencyModes = await Self.app.models.ZoneAgencyMode.find({
|
||||
where: {
|
||||
agencyModeFk: route.agencyModeFk
|
||||
}
|
||||
});
|
||||
|
||||
const zoneIds = [];
|
||||
for (let zoneAgencyMode of zoneAgencyModes)
|
||||
zoneIds.push(zoneAgencyMode.zoneFk);
|
||||
|
||||
const tickets = await Self.app.models.Ticket.find({
|
||||
where: {
|
||||
ageconyModeFk: route.agencyModeFk,
|
||||
zoneFk: {inq: zoneIds}
|
||||
}
|
||||
});
|
||||
|
||||
return tickets;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('route getSuggestedTickets()', () => {
|
||||
it('should return an array of suggested tickets', async() => {
|
||||
const result = await app.models.Route.getSuggestedTickets(1);
|
||||
|
||||
const length = result.length;
|
||||
const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
|
||||
|
||||
expect(result.length).toEqual(4);
|
||||
expect(anyResult.zoneFk).toEqual(1);
|
||||
expect(anyResult.agencyModeFk).toEqual(1);
|
||||
});
|
||||
});
|
|
@ -7,6 +7,7 @@ module.exports = Self => {
|
|||
require('../methods/route/getDeliveryPoint')(Self);
|
||||
require('../methods/route/insertTicket')(Self);
|
||||
require('../methods/route/clone')(Self);
|
||||
require('../methods/route/getSuggestedTickets')(Self);
|
||||
|
||||
Self.validate('kmStart', validateDistance, {
|
||||
message: 'Distance must be lesser than 1000'
|
||||
|
|
|
@ -110,11 +110,12 @@
|
|||
question="Delete ticket from route?"
|
||||
on-accept="$ctrl.removeTicketFromRoute()">
|
||||
</vn-confirm>
|
||||
<vn-crud-model
|
||||
<vn-crud-model
|
||||
vn-id="possibleTicketsModel"
|
||||
url="Tickets"
|
||||
filter="$ctrl.possibleTicketsFilter"
|
||||
data="$ctrl.possibleTickets">
|
||||
url="Routes/{{$ctrl.$params.id}}/getSuggestedTickets"
|
||||
order="priority ASC"
|
||||
data="$ctrl.possibleTickets"
|
||||
auto-load="true">
|
||||
</vn-crud-model>
|
||||
<vn-dialog
|
||||
vn-id="possibleTicketsDialog"
|
||||
|
|
|
@ -9,8 +9,6 @@ class Controller extends Section {
|
|||
|
||||
set route(value) {
|
||||
this._route = value;
|
||||
if (value)
|
||||
this.buildPossibleTicketsFilter();
|
||||
}
|
||||
|
||||
get isChecked() {
|
||||
|
@ -22,32 +20,6 @@ class Controller extends Section {
|
|||
return false;
|
||||
}
|
||||
|
||||
buildPossibleTicketsFilter() {
|
||||
let minDate = new Date(this.route.finished);
|
||||
minDate.setHours(0, 0, 0, 0);
|
||||
|
||||
let maxDate = new Date(this.route.finished);
|
||||
maxDate.setHours(23, 59, 59, 59);
|
||||
|
||||
this.possibleTicketsFilter = {
|
||||
where: {
|
||||
zoneFk: this.route.zoneFk,
|
||||
routeFk: null,
|
||||
landed: {between: [minDate, maxDate]},
|
||||
},
|
||||
include: [
|
||||
{
|
||||
relation: 'warehouse',
|
||||
scope: {
|
||||
fields: ['name']
|
||||
},
|
||||
}, {
|
||||
relation: 'address'
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
getHighestPriority() {
|
||||
let highestPriority = Math.max(...this.$.model.data.map(tag => {
|
||||
return tag.priority;
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
"Zone": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"ZoneAgencyMode": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"ZoneClosure": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "ZoneAgencyMode",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "zoneAgencyMode"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
"type": "number"
|
||||
},
|
||||
"agencyModeFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"zoneFk": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "READ",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue