#6434 - SignIn issue_improve-signInLogMethod #1848
|
@ -0,0 +1,24 @@
|
||||||
|
DELETE FROM `salix`.`ACL`
|
||||||
|
WHERE
|
||||||
|
model = 'Route'
|
||||||
|
AND property = '*'
|
||||||
|
AND accessType = 'READ';
|
||||||
|
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('Route', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Route', 'findOne', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Route', 'getRoutesByWorker', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Route', 'canViewAllRoute', 'READ', 'ALLOW', 'ROLE', 'deliveryBoss'),
|
||||||
|
('Route', 'filter', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Route', 'getSuggestedTickets', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Route', 'guessPriority', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Route', 'insertTicket', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Route', 'getDeliveryPoint', 'READ', 'ALLOW', 'ROLE', 'deliveryBoss'),
|
||||||
|
('Route', 'summary', 'READ', 'ALLOW', 'ROLE', 'employee');
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO salix.AccessToken (id, ttl, scopes, created, userId, outdated) VALUES('1z0GILWTs8huKrJGp7Fj0PvHaGA8Gg9DTNhm6nn6AfhkNJygeVUHMZKOGfMPp0xO', 1209600, NULL, '2023-07-17 13:34:10', 56, '2023-07-31 13:34:10');
|
||||||
|
INSERT INTO salix.AccessToken (id, ttl, scopes, created, userId, outdated) VALUES('1z0GILWTs8huKrJGp7Fj0PvHaGA8Gg9DTNhm6nn6AfhkNJygeVUHMZKOGfMPp0xP', 1209600, NULL, '2023-07-17 13:34:10', 57, '2023-07-31 13:34:10');
|
|
@ -69,6 +69,7 @@ TABLES=(
|
||||||
volumeConfig
|
volumeConfig
|
||||||
workCenter
|
workCenter
|
||||||
companyI18n
|
companyI18n
|
||||||
|
silexACL
|
||||||
)
|
)
|
||||||
dump_tables ${TABLES[@]}
|
dump_tables ${TABLES[@]}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('getRoutesByWorker', () => {
|
||||||
|
fit('should return the routes of the worker can view all routes', async() => {
|
||||||
|
const deliveryBossId = 57;
|
||||||
|
const ctx = {req: {accessToken: {userId: deliveryBossId}}};
|
||||||
|
const result = await models.Route.getRoutesByWorker(ctx);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(7);
|
||||||
|
});
|
||||||
|
|
||||||
|
fit('should return the routes of the worker can not view all routes', async() => {
|
||||||
|
const deliveryId = 56;
|
||||||
|
const ctx = {req: {accessToken: {userId: deliveryId}}};
|
||||||
|
const result = await models.Route.getRoutesByWorker(ctx);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(5);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,7 +1,7 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('getDeliveryPoint', {
|
Self.remoteMethod('getDeliveryPoint', {
|
||||||
description: 'get the deliveryPoint address',
|
description: 'get the deliveryPoint address',
|
||||||
accessType: 'WRITE',
|
accessType: 'READ',
|
||||||
accepts: {
|
accepts: {
|
||||||
arg: 'vehicleId',
|
arg: 'vehicleId',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('getRoutesByWorker', {
|
||||||
|
description: 'Return the routes by worker',
|
||||||
|
accessType: 'READ',
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/get-routes-by-worker`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getRoutesByWorker = async(ctx, options) => {
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const canViewAll = await Self.app.models.ACL.checkAccessAcl(ctx, 'Route', 'canViewAllRoute', 'READ');
|
||||||
|
const condition = canViewAll ? `ay.warehouseFK = uc.warehouseFk` : `r.workerFk = ${userId}`;
|
||||||
|
|
||||||
|
return Self.rawSql(`
|
||||||
|
SELECT concat(w.firstName , ' ', w.lastName) driver,
|
||||||
|
r.id,
|
||||||
|
Date_format(r.time, '%H:%i') hour,
|
||||||
|
r.created,
|
||||||
|
r.m3,
|
||||||
|
v.numberPlate,
|
||||||
|
a.name,
|
||||||
|
r.kmStart,
|
||||||
|
r.kmEnd,
|
||||||
|
r.started,
|
||||||
|
r.finished
|
||||||
|
FROM vn.route r
|
||||||
|
JOIN vn.vehicle v ON r.vehicleFk = v.id
|
||||||
|
JOIN vn.agencyMode a ON r.agencyModeFk = a.id
|
||||||
|
JOIN vn.agency ay ON a.agencyFk = ay.id
|
||||||
|
JOIN vn.worker w ON r.workerFk = w.id
|
||||||
|
LEFT JOIN vn.userConfig uc ON uc.userFk = ?
|
||||||
|
WHERE (r.created = util.VN_CURDATE() OR r.created = TIMESTAMPADD(day, 1, util.VN_CURDATE()))
|
||||||
|
AND ${condition}
|
||||||
|
ORDER BY r.created ASC, r.time ASC, a.name ASC
|
||||||
|
`, [userId], myOptions);
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,7 +1,7 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('guessPriority', {
|
Self.remoteMethodCtx('guessPriority', {
|
||||||
description: 'Changes automatically the priority of the tickets in a route',
|
description: 'Changes automatically the priority of the tickets in a route',
|
||||||
accessType: 'READ',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
@ -15,7 +15,7 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/:id/guessPriority`,
|
path: `/:id/guessPriority`,
|
||||||
verb: 'GET'
|
verb: 'PATCH'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ const UserError = require('vn-loopback/util/user-error');
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('insertTicket', {
|
Self.remoteMethod('insertTicket', {
|
||||||
description: 'Check if the ticket can be insert into the route and insert it',
|
description: 'Check if the ticket can be insert into the route and insert it',
|
||||||
accessType: 'READ',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'routeId',
|
arg: 'routeId',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
|
@ -14,6 +14,7 @@ module.exports = Self => {
|
||||||
require('../methods/route/driverRouteEmail')(Self);
|
require('../methods/route/driverRouteEmail')(Self);
|
||||||
require('../methods/route/sendSms')(Self);
|
require('../methods/route/sendSms')(Self);
|
||||||
require('../methods/route/downloadZip')(Self);
|
require('../methods/route/downloadZip')(Self);
|
||||||
|
require('../methods/route/getRoutesByWorker')(Self);
|
||||||
|
|
||||||
Self.validate('kmStart', validateDistance, {
|
Self.validate('kmStart', validateDistance, {
|
||||||
message: 'Distance must be lesser than 1000'
|
message: 'Distance must be lesser than 1000'
|
||||||
|
|
|
@ -120,7 +120,7 @@ class Controller extends Section {
|
||||||
|
|
||||||
guessPriority() {
|
guessPriority() {
|
||||||
let query = `Routes/${this.$params.id}/guessPriority/`;
|
let query = `Routes/${this.$params.id}/guessPriority/`;
|
||||||
this.$http.get(query).then(() => {
|
this.$http.patch(query).then(() => {
|
||||||
this.vnApp.showSuccess(this.$t('Order changed'));
|
this.vnApp.showSuccess(this.$t('Order changed'));
|
||||||
this.$.model.refresh();
|
this.$.model.refresh();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue