Tarea #1462 Route.descriptior Añadir menú - actualizar m3
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-06-05 13:51:34 +02:00
parent e895e90232
commit 3a338739d1
10 changed files with 152 additions and 26 deletions

View File

@ -1,2 +1,3 @@
INSERT INTO `salix`.`ACL` ( `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ( 'ClientDms', 'remove', 'WRITE', 'ALLOW', 'ROLE', 'employee');
INSERT INTO `salix`.`ACL` ( `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ( 'ClientDms', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Route', 'updateVolume', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss');

View File

@ -364,13 +364,13 @@ INSERT INTO `vn`.`creditInsurance`(`id`, `creditClassification`, `credit`, `crea
INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`)
VALUES
(1, '1899-12-30 12:15:00', 56, CURDATE(), 1, 1, 'first route', null, 10, CURDATE(), CURDATE()),
(2, '1899-12-30 13:20:00', 56, CURDATE(), 1, 1, 'second route', 4.2, 20, CURDATE(), CURDATE()),
(3, '1899-12-30 14:30:00', 56, CURDATE(), 2, 7, 'third route', 5.3, 30, CURDATE(), CURDATE()),
(4, '1899-12-30 15:45:00', 56, CURDATE(), 3, 7, 'fourth route', 6.4, 40, CURDATE(), CURDATE()),
(5, '1899-12-30 16:00:00', 56, CURDATE(), 4, 8, 'fifth route', 7.5, 50, CURDATE(), CURDATE()),
(6, null, 57, CURDATE(), 5, 8, 'sixth route', 8.6, 60, CURDATE(), CURDATE()),
(7, null, 57, CURDATE(), 6, null, 'seventh route', 9.7, 70, CURDATE(), CURDATE());
(1, '1899-12-30 12:15:00', 56, CURDATE(), 1, 1, 'first route', 0.2, 10, CURDATE(), CURDATE()),
(2, '1899-12-30 13:20:00', 56, CURDATE(), 1, 1, 'second route', null, 20, CURDATE(), CURDATE()),
(3, '1899-12-30 14:30:00', 56, CURDATE(), 2, 7, 'third route', null, 30, CURDATE(), CURDATE()),
(4, '1899-12-30 15:45:00', 56, CURDATE(), 3, 7, 'fourth route', 0.1, 40, CURDATE(), CURDATE()),
(5, '1899-12-30 16:00:00', 56, CURDATE(), 4, 8, 'fifth route', null, 50, CURDATE(), CURDATE()),
(6, null, 57, CURDATE(), 5, 8, 'sixth route', null, 60, CURDATE(), CURDATE()),
(7, null, 57, CURDATE(), 6, null, 'seventh route', null, 70, CURDATE(), CURDATE());
INSERT INTO `vn2008`.`empresa_grupo`(`empresa_grupo_id`, `grupo`)
VALUES

View File

@ -45,7 +45,7 @@ describe('Route filter()', () => {
it('should return the routes matching "m3"', async() => {
let ctx = {
args: {
m3: 4.2,
m3: 0.1,
}
};

View File

@ -0,0 +1,44 @@
const app = require('vn-loopback/server/server');
describe('route updateVolume()', () => {
const routeId = 1;
const workerFk = 9;
const ctx = {req: {accessToken: {userId: workerFk}}};
let originalRoute;
let ticketRestore;
afterAll(async done => {
await originalRoute.updateAttributes({m3: 0.2});
await ticketRestore.updateAttributes({routeFk: 4});
done();
});
it('should confirm the original volume of the route is the expected', async() => {
originalRoute = await app.models.Route.findById(routeId);
expect(originalRoute.m3).toEqual(0.2);
});
it('should confirm the route volume is updated when a ticket is added', async() => {
ticketRestore = await app.models.Ticket.findById(8);
let updatedTicket = await app.models.Ticket.findById(8);
await updatedTicket.updateAttributes({routeFk: routeId});
await app.models.Route.updateVolume(ctx, routeId);
let updatedRoute = await app.models.Route.findById(routeId);
expect(updatedRoute.m3).not.toEqual(originalRoute.m3);
});
// 1462
xit('should confirm the change is logged ', async() => {
let instanceValue = {m3: 0.3};
let filterValue = JSON.stringify(instanceValue);
let filter = {where: {newInstance: filterValue}};
console.log(filter);
let routeLog = await app.models.RouteLog.find(filter);
console.log(routeLog);
expect(routeLog.length).toBeGreaterThan(0);
});
});

View File

@ -0,0 +1,42 @@
module.exports = Self => {
Self.remoteMethodCtx('updateVolume', {
description: 'Update the volume in a route',
accessType: 'WRITE',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'Route id',
http: {source: 'path'}
},
returns: {
type: 'number',
root: true
},
http: {
path: `/:id/updateVolume`,
verb: 'POST'
}
});
Self.updateVolume = async(ctx, id) => {
let query = `CALL vn.routeUpdateM3(?)`;
let userId = ctx.req.accessToken.userId;
let originalRoute = await Self.app.models.Route.findById(id);
await Self.rawSql(query, [id]);
let updatedRoute = await Self.app.models.Route.findById(id);
let logRecord = {
originFk: id,
userFk: userId,
action: 'update',
changedModel: 'Route',
changedModelId: id,
oldInstance: {m3: originalRoute.m3},
newInstance: {m3: updatedRoute.m3}
};
return await Self.app.models.RouteLog.create(logRecord);
};
};

View File

@ -3,4 +3,5 @@ module.exports = Self => {
require('../methods/route/summary')(Self);
require('../methods/route/getTickets')(Self);
require('../methods/route/guessPriority')(Self);
require('../methods/route/updateVolume')(Self);
};

View File

@ -13,7 +13,8 @@
value-field="callback"
translate-fields="['name']"
data="$ctrl.moreOptions"
on-change="$ctrl.onMoreChange(value)">
on-change="$ctrl.onMoreChange(value)"
on-open="$ctrl.onMoreOpen()">
</vn-icon-menu>
</div>
<div class="body">
@ -70,3 +71,8 @@
</div>
</div>
</div>
<vn-confirm
vn-id="updateVolumeConfirmation"
on-response="$ctrl.updateVolume(response)"
question="Are you sure you want to book this invoice?">
</vn-confirm>

View File

@ -1,16 +1,29 @@
import ngModule from '../module';
import {createDecipher} from 'crypto';
class Controller {
constructor($, $http, vnApp, $translate) {
constructor($, $http, vnApp, $translate, aclService) {
this.$http = $http;
this.vnApp = vnApp;
this.$translate = $translate;
this.$ = $;
this.aclService = aclService;
this.moreOptions = [
{callback: this.showRouteReport, name: 'Show route report'},
{callback: this.sendRouteReport, name: 'Send route report'}
{callback: this.sendRouteReport, name: 'Send route report'},
{callback: this.showUpdateVolumeDialog, name: 'Update volume', acl: 'deliveryBoss'}
];
}
onMoreOpen() {
let options = this.moreOptions.filter(option => {
const hasAclProperty = Object.hasOwnProperty.call(option, 'acl');
return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl]));
});
this.$.moreButton.data = options;
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
@ -34,9 +47,23 @@ class Controller {
this.vnApp.showSuccess(this.$translate.instant('Report sent'));
});
}
showUpdateVolumeDialog() {
this.$.updateVolumeConfirmation.show();
}
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
updateVolume(response) {
if (response === 'ACCEPT') {
let url = `/route/api/Routes/${this.route.id}/updateVolume`;
this.$http.post(url).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Volume updated'));
this.card.reload();
});
}
}
}
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate', 'aclService'];
ngModule.component('vnRouteDescriptor', {
template: require('./index.html'),
@ -44,5 +71,8 @@ ngModule.component('vnRouteDescriptor', {
route: '<',
quicklinks: '<'
},
require: {
card: '^vnRouteCard'
},
controller: Controller
});

View File

@ -2,3 +2,5 @@ Volume exceded: Volumen excedido
Volume: Volumen
Send route report: Enviar informe de ruta
Show route report: Ver informe de ruta
Update volume: Actualizar volumen
Volume updated: Volumen actualizado