Merge pull request '#3015 feat(unlink): tickets link to route can now be removed from the suggested tickets to route' (#884) from 3015-route_tickets_unlink into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #884 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
eb9d349b17
|
@ -25,6 +25,7 @@ module.exports = Self => {
|
|||
Object.assign(myOptions, options);
|
||||
|
||||
const route = await Self.app.models.Route.findById(id, null, myOptions);
|
||||
|
||||
const zoneAgencyModes = await Self.app.models.ZoneAgencyMode.find({
|
||||
where: {
|
||||
agencyModeFk: route.agencyModeFk
|
||||
|
@ -52,6 +53,12 @@ module.exports = Self => {
|
|||
fields: ['id', 'name']
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'zone',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'address',
|
||||
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/clone')(Self);
|
||||
require('../methods/route/getSuggestedTickets')(Self);
|
||||
require('../methods/route/unlink')(Self);
|
||||
|
||||
Self.validate('kmStart', validateDistance, {
|
||||
message: 'Distance must be lesser than 1000'
|
||||
|
|
|
@ -150,7 +150,7 @@
|
|||
</vn-th>
|
||||
<vn-th expand>PC</vn-th>
|
||||
<vn-th>Address</vn-th>
|
||||
<vn-th shrink>Warehouse</vn-th>
|
||||
<vn-th shrink>Zone</vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
|
@ -174,7 +174,15 @@
|
|||
<vn-td shrink>{{::ticket.address.city}}</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>{{::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-tbody>
|
||||
</vn-table>
|
||||
|
@ -196,3 +204,11 @@
|
|||
<vn-client-descriptor-popover
|
||||
vn-id="client-descriptor">
|
||||
</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) {
|
||||
const selectedItems = [];
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint max-len: ["error", { "code": 150 }]*/
|
||||
import './index';
|
||||
|
||||
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()', () => {
|
||||
it('should return the selected items', () => {
|
||||
let items = [
|
||||
|
|
|
@ -11,4 +11,5 @@ The selected ticket is not suitable for this route: El ticket seleccionado no es
|
|||
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 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": {
|
||||
"id": {
|
||||
"id": true,
|
||||
"type": "Number",
|
||||
"type": "number",
|
||||
"forceId": false
|
||||
},
|
||||
"name": {
|
||||
"type": "String",
|
||||
"type": "string",
|
||||
"required": false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"name": {
|
||||
"type": "String",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
"hour": {
|
||||
|
@ -24,22 +24,22 @@
|
|||
"required": true
|
||||
},
|
||||
"travelingDays": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"price": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"bonus": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"isVolumetric": {
|
||||
"type": "Boolean"
|
||||
"type": "boolean"
|
||||
},
|
||||
"inflation": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
},
|
||||
"itemMaxSize": {
|
||||
"type": "Number"
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
Loading…
Reference in New Issue