#3015 feat(unlink): tickets link to route can now be removed from the suggested tickets to route #884
|
@ -25,6 +25,7 @@ module.exports = Self => {
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const route = await Self.app.models.Route.findById(id, null, myOptions);
|
const route = await Self.app.models.Route.findById(id, null, myOptions);
|
||||||
|
|
||||||
const zoneAgencyModes = await Self.app.models.ZoneAgencyMode.find({
|
const zoneAgencyModes = await Self.app.models.ZoneAgencyMode.find({
|
||||||
where: {
|
where: {
|
||||||
agencyModeFk: route.agencyModeFk
|
agencyModeFk: route.agencyModeFk
|
||||||
|
@ -52,6 +53,12 @@ module.exports = Self => {
|
||||||
fields: ['id', 'name']
|
fields: ['id', 'name']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
relation: 'zone',
|
||||||
|
scope: {
|
||||||
|
fields: ['id', 'name']
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
relation: 'address',
|
relation: 'address',
|
||||||
scope: {
|
scope: {
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('route unlink()', () => {
|
||||||
|
it('should show no tickets since the link between zone and route for the give agencymode was removed', async() => {
|
||||||
|
const tx = await models.ZoneAgencyMode.beginTransaction({});
|
||||||
|
const agencyModeId = 1;
|
||||||
|
const zoneId = 1;
|
||||||
|
routeId = 1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
let zoneAgencyModes = await models.ZoneAgencyMode.find(null, options);
|
||||||
|
let tickets = await models.Route.getSuggestedTickets(routeId, options);
|
||||||
|
|
||||||
|
expect(zoneAgencyModes.length).toEqual(4);
|
||||||
|
expect(tickets.length).toEqual(3);
|
||||||
|
|
||||||
|
await models.Route.unlink(agencyModeId, zoneId, options);
|
||||||
|
|
||||||
|
zoneAgencyModes = await models.ZoneAgencyMode.find(null, options);
|
||||||
|
tickets = await models.Route.getSuggestedTickets(routeId, options);
|
||||||
|
|
||||||
|
expect(zoneAgencyModes.length).toEqual(3);
|
||||||
|
expect(tickets.length).toEqual(0);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,42 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('unlink', {
|
||||||
|
description: 'Removes the matching entries from zoneAgencyMode',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'agencyModeId',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The agencyMode id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'zoneId',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The zone id',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/unlink`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.unlink = async(agencyModeId, zoneId, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const where = {
|
||||||
|
agencyModeFk: agencyModeId,
|
||||||
|
zoneFk: zoneId
|
||||||
|
};
|
||||||
|
|
||||||
|
await Self.app.models.ZoneAgencyMode.destroyAll(where, myOptions);
|
||||||
|
};
|
||||||
|
};
|
|
@ -8,6 +8,7 @@ module.exports = Self => {
|
||||||
require('../methods/route/insertTicket')(Self);
|
require('../methods/route/insertTicket')(Self);
|
||||||
require('../methods/route/clone')(Self);
|
require('../methods/route/clone')(Self);
|
||||||
require('../methods/route/getSuggestedTickets')(Self);
|
require('../methods/route/getSuggestedTickets')(Self);
|
||||||
|
require('../methods/route/unlink')(Self);
|
||||||
|
|
||||||
Self.validate('kmStart', validateDistance, {
|
Self.validate('kmStart', validateDistance, {
|
||||||
message: 'Distance must be lesser than 1000'
|
message: 'Distance must be lesser than 1000'
|
||||||
|
|
|
@ -150,7 +150,7 @@
|
||||||
</vn-th>
|
</vn-th>
|
||||||
<vn-th expand>PC</vn-th>
|
<vn-th expand>PC</vn-th>
|
||||||
<vn-th>Address</vn-th>
|
<vn-th>Address</vn-th>
|
||||||
<vn-th shrink>Warehouse</vn-th>
|
<vn-th shrink>Zone</vn-th>
|
||||||
</vn-tr>
|
</vn-tr>
|
||||||
</vn-thead>
|
</vn-thead>
|
||||||
<vn-tbody>
|
<vn-tbody>
|
||||||
|
@ -174,7 +174,15 @@
|
||||||
<vn-td shrink>{{::ticket.address.city}}</vn-td>
|
<vn-td shrink>{{::ticket.address.city}}</vn-td>
|
||||||
<vn-td number shrink>{{::ticket.address.postalCode}}</vn-td>
|
<vn-td number shrink>{{::ticket.address.postalCode}}</vn-td>
|
||||||
<vn-td expand title="{{::ticket.address.street}}">{{::ticket.address.street}}</vn-td>
|
<vn-td expand title="{{::ticket.address.street}}">{{::ticket.address.street}}</vn-td>
|
||||||
<vn-td expand>{{::ticket.warehouse.name}}</vn-td>
|
<vn-td expand>
|
||||||
|
{{::ticket.zone.name}}
|
||||||
|
<vn-icon-button
|
||||||
|
icon="link_off"
|
||||||
|
class="pointer"
|
||||||
|
translate-attr="{title: 'Unlink zone: {{::ticket.zone.name}} from agency: {{::ticket.agencyMode.name}}'}"
|
||||||
|
ng-click="unlinkZoneConfirmation.show(ticket)">
|
||||||
|
</vn-icon-button>
|
||||||
|
</vn-td>
|
||||||
</vn-tr>
|
</vn-tr>
|
||||||
</vn-tbody>
|
</vn-tbody>
|
||||||
</vn-table>
|
</vn-table>
|
||||||
|
@ -196,3 +204,11 @@
|
||||||
<vn-client-descriptor-popover
|
<vn-client-descriptor-popover
|
||||||
vn-id="client-descriptor">
|
vn-id="client-descriptor">
|
||||||
</vn-client-descriptor-popover>
|
</vn-client-descriptor-popover>
|
||||||
|
|
||||||
|
<!-- Unlink zone confirmation dialog -->
|
||||||
|
<vn-confirm
|
||||||
|
vn-id="unlinkZoneConfirmation"
|
||||||
|
on-accept="$ctrl.unlinkZone($data)"
|
||||||
|
question="{{$ctrl.confirmationMessage}}"
|
||||||
|
message="Unlink selected zone?">
|
||||||
|
</vn-confirm>
|
|
@ -37,6 +37,19 @@ class Controller extends Section {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlinkZone(ticket) {
|
||||||
|
const params = {
|
||||||
|
agencyModeId: this.route.agencyModeFk,
|
||||||
|
zoneId: ticket.zoneFk,
|
||||||
|
};
|
||||||
|
|
||||||
|
const query = `Routes/unlink`;
|
||||||
|
this.$http.post(query, params).then(() => {
|
||||||
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
|
this.$.possibleTicketsModel.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getSelectedItems(items) {
|
getSelectedItems(items) {
|
||||||
const selectedItems = [];
|
const selectedItems = [];
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint max-len: ["error", { "code": 150 }]*/
|
||||||
import './index';
|
import './index';
|
||||||
|
|
||||||
describe('Route', () => {
|
describe('Route', () => {
|
||||||
|
@ -73,6 +74,32 @@ describe('Route', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('unlink()', () => {
|
||||||
|
it('should call the route unlink endpoint with the agency and zone ids', () => {
|
||||||
|
controller.$.possibleTicketsModel = {refresh: jest.fn()};
|
||||||
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
||||||
|
controller.route = {
|
||||||
|
agencyModeFk: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
const ticket = {
|
||||||
|
zoneFk: 2,
|
||||||
|
};
|
||||||
|
const params = {
|
||||||
|
agencyModeId: controller.route.agencyModeFk,
|
||||||
|
zoneId: ticket.zoneFk,
|
||||||
|
};
|
||||||
|
|
||||||
|
$httpBackend.expectPOST(`Routes/unlink`, params).respond('ok');
|
||||||
|
controller.unlinkZone(ticket);
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||||
|
expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('getSelectedItems()', () => {
|
describe('getSelectedItems()', () => {
|
||||||
it('should return the selected items', () => {
|
it('should return the selected items', () => {
|
||||||
let items = [
|
let items = [
|
||||||
|
|
|
@ -12,3 +12,4 @@ PC: CP
|
||||||
The route's vehicle doesn't have a delivery point: El vehículo de la ruta no tiene un punto de entrega
|
The route's vehicle doesn't have a delivery point: El vehículo de la ruta no tiene un punto de entrega
|
||||||
The route doesn't have a vehicle: La ruta no tiene un vehículo
|
The route doesn't have a vehicle: La ruta no tiene un vehículo
|
||||||
Population: Población
|
Population: Población
|
||||||
|
Unlink selected zone?: Desvincular zona seleccionada?
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "Number",
|
"type": "number",
|
||||||
"forceId": false
|
"forceId": false
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"type": "String",
|
"type": "string",
|
||||||
"required": false
|
"required": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"type": "String",
|
"type": "string",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"hour": {
|
"hour": {
|
||||||
|
@ -24,22 +24,22 @@
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"travelingDays": {
|
"travelingDays": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"price": {
|
"price": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"bonus": {
|
"bonus": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"isVolumetric": {
|
"isVolumetric": {
|
||||||
"type": "Boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"inflation": {
|
"inflation": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"itemMaxSize": {
|
"itemMaxSize": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
Loading…
Reference in New Issue