From 639d5963a3517463d0364ec73276583b42cb00b5 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 17 Jul 2023 13:50:07 +0200 Subject: [PATCH 1/4] refs #6028 get_routes --- db/changes/233001/00-getRoutesByWorker.sql | 24 ++++++++++ db/export-data.sh | 1 + .../client/specs/getRoutesByWorker.spec.js | 19 ++++++++ .../back/methods/route/getDeliveryPoint.js | 2 +- .../back/methods/route/getRoutesByWorker.js | 48 +++++++++++++++++++ .../route/back/methods/route/guessPriority.js | 4 +- .../route/back/methods/route/insertTicket.js | 2 +- modules/route/back/models/route.js | 1 + modules/route/front/tickets/index.js | 2 +- 9 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 db/changes/233001/00-getRoutesByWorker.sql create mode 100644 modules/client/back/methods/client/specs/getRoutesByWorker.spec.js create mode 100644 modules/route/back/methods/route/getRoutesByWorker.js diff --git a/db/changes/233001/00-getRoutesByWorker.sql b/db/changes/233001/00-getRoutesByWorker.sql new file mode 100644 index 000000000..aa612d48e --- /dev/null +++ b/db/changes/233001/00-getRoutesByWorker.sql @@ -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'); diff --git a/db/export-data.sh b/db/export-data.sh index 1df4db030..914564093 100755 --- a/db/export-data.sh +++ b/db/export-data.sh @@ -69,6 +69,7 @@ TABLES=( volumeConfig workCenter companyI18n + silexACL ) dump_tables ${TABLES[@]} diff --git a/modules/client/back/methods/client/specs/getRoutesByWorker.spec.js b/modules/client/back/methods/client/specs/getRoutesByWorker.spec.js new file mode 100644 index 000000000..b43fe49d2 --- /dev/null +++ b/modules/client/back/methods/client/specs/getRoutesByWorker.spec.js @@ -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); + }); +}); diff --git a/modules/route/back/methods/route/getDeliveryPoint.js b/modules/route/back/methods/route/getDeliveryPoint.js index e5a50805a..3359f666e 100644 --- a/modules/route/back/methods/route/getDeliveryPoint.js +++ b/modules/route/back/methods/route/getDeliveryPoint.js @@ -1,7 +1,7 @@ module.exports = Self => { Self.remoteMethod('getDeliveryPoint', { description: 'get the deliveryPoint address', - accessType: 'WRITE', + accessType: 'READ', accepts: { arg: 'vehicleId', type: 'number', diff --git a/modules/route/back/methods/route/getRoutesByWorker.js b/modules/route/back/methods/route/getRoutesByWorker.js new file mode 100644 index 000000000..0a6f59816 --- /dev/null +++ b/modules/route/back/methods/route/getRoutesByWorker.js @@ -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); + }; +}; diff --git a/modules/route/back/methods/route/guessPriority.js b/modules/route/back/methods/route/guessPriority.js index c6b2a9b74..749075388 100644 --- a/modules/route/back/methods/route/guessPriority.js +++ b/modules/route/back/methods/route/guessPriority.js @@ -1,7 +1,7 @@ module.exports = Self => { Self.remoteMethodCtx('guessPriority', { description: 'Changes automatically the priority of the tickets in a route', - accessType: 'READ', + accessType: 'WRITE', accepts: [{ arg: 'id', type: 'number', @@ -15,7 +15,7 @@ module.exports = Self => { }, http: { path: `/:id/guessPriority`, - verb: 'GET' + verb: 'PATCH' } }); diff --git a/modules/route/back/methods/route/insertTicket.js b/modules/route/back/methods/route/insertTicket.js index f78e1cb83..4ac8bad1a 100644 --- a/modules/route/back/methods/route/insertTicket.js +++ b/modules/route/back/methods/route/insertTicket.js @@ -3,7 +3,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethod('insertTicket', { description: 'Check if the ticket can be insert into the route and insert it', - accessType: 'READ', + accessType: 'WRITE', accepts: [{ arg: 'routeId', type: 'number', diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js index 883f4597e..fe88f2e08 100644 --- a/modules/route/back/models/route.js +++ b/modules/route/back/models/route.js @@ -14,6 +14,7 @@ module.exports = Self => { require('../methods/route/driverRouteEmail')(Self); require('../methods/route/sendSms')(Self); require('../methods/route/downloadZip')(Self); + require('../methods/route/getRoutesByWorker')(Self); Self.validate('kmStart', validateDistance, { message: 'Distance must be lesser than 1000' diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js index 8789708ac..a1b97005e 100644 --- a/modules/route/front/tickets/index.js +++ b/modules/route/front/tickets/index.js @@ -120,7 +120,7 @@ class Controller extends Section { 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.$.model.refresh(); }); From e856de0cfd8681f05b1639d003074545f38f9f39 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 22 Nov 2023 15:54:38 +0100 Subject: [PATCH 2/4] feat: refs #6028 test --- .../00-getRoutesByWorker.sql | 4 -- .../client/specs/getRoutesByWorker.spec.js | 19 ------ modules/route/back/methods/route/filter.js | 6 +- .../route/back/methods/route/getByWorker.js | 66 +++++++++++++++++++ .../back/methods/route/getRoutesByWorker.js | 48 -------------- .../methods/route/specs/getByWorker.spec.js | 39 +++++++++++ modules/route/back/models/route.js | 2 +- 7 files changed, 110 insertions(+), 74 deletions(-) rename db/changes/{233001 => 234801}/00-getRoutesByWorker.sql (71%) delete mode 100644 modules/client/back/methods/client/specs/getRoutesByWorker.spec.js create mode 100644 modules/route/back/methods/route/getByWorker.js delete mode 100644 modules/route/back/methods/route/getRoutesByWorker.js create mode 100644 modules/route/back/methods/route/specs/getByWorker.spec.js diff --git a/db/changes/233001/00-getRoutesByWorker.sql b/db/changes/234801/00-getRoutesByWorker.sql similarity index 71% rename from db/changes/233001/00-getRoutesByWorker.sql rename to db/changes/234801/00-getRoutesByWorker.sql index aa612d48e..bdc4a246e 100644 --- a/db/changes/233001/00-getRoutesByWorker.sql +++ b/db/changes/234801/00-getRoutesByWorker.sql @@ -18,7 +18,3 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `pri ('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'); diff --git a/modules/client/back/methods/client/specs/getRoutesByWorker.spec.js b/modules/client/back/methods/client/specs/getRoutesByWorker.spec.js deleted file mode 100644 index b43fe49d2..000000000 --- a/modules/client/back/methods/client/specs/getRoutesByWorker.spec.js +++ /dev/null @@ -1,19 +0,0 @@ -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); - }); -}); diff --git a/modules/route/back/methods/route/filter.js b/modules/route/back/methods/route/filter.js index fc35e979f..afefa77d1 100644 --- a/modules/route/back/methods/route/filter.js +++ b/modules/route/back/methods/route/filter.js @@ -105,7 +105,7 @@ module.exports = Self => { } }); - filter = mergeFilters(ctx.args.filter, {where}); + filter = mergeFilters(filter, {where}); let stmts = []; let stmt; @@ -129,9 +129,11 @@ module.exports = Self => { r.description, am.name agencyName, u.name AS workerUserName, - v.numberPlate AS vehiclePlateNumber + v.numberPlate AS vehiclePlateNumber, + Date_format(r.time, '%H:%i') hour FROM route r LEFT JOIN agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN agency a ON a.id = am.agencyFk LEFT JOIN vehicle v ON v.id = r.vehicleFk LEFT JOIN worker w ON w.id = r.workerFk LEFT JOIN account.user u ON u.id = w.id` diff --git a/modules/route/back/methods/route/getByWorker.js b/modules/route/back/methods/route/getByWorker.js new file mode 100644 index 000000000..2f8a286e6 --- /dev/null +++ b/modules/route/back/methods/route/getByWorker.js @@ -0,0 +1,66 @@ +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; + +module.exports = Self => { + Self.remoteMethodCtx('getByWorker', { + description: 'Return the routes by worker', + accessType: 'READ', + returns: { + type: ['object'], + root: true + }, + http: { + path: `/getByWorker`, + verb: 'GET' + } + }); + + Self.getByWorker = async ctx => { + const models = Self.app.models; + const userId = ctx.req.accessToken.userId; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const canViewAll = await models.ACL.checkAccessAcl(ctx, 'Route', 'canViewAllRoute', 'READ'); + let filterGrant = {}; + console.log(userId); + console.log(canViewAll); + if (canViewAll) { + const userConfig = await models.UserConfig.getUserConfig(ctx, myOptions); + filterGrant = { + where: {'a.warehouseFk': userConfig.warehouseFk} + }; + } else { + filterGrant = { + where: {'r.workerFk': userId} + }; + } + + const currentDate = Date.vnNew(); + currentDate.setHours(0, 0, 0, 0); + const nextDay = Date.vnNew(); + nextDay.setDate(currentDate.getDate() + 1); + + const filter = { + where: { + and: [ + { + or: [ + {'r.created': currentDate}, + {'r.created': nextDay} + ] + } + ] + }, + order: [ + 'r.created ASC', + 'r.time ASC', + 'am.name ASC' + ] + }; + + const result = await Self.filter(ctx, mergeFilters(filter, filterGrant)); + return result; + }; +}; diff --git a/modules/route/back/methods/route/getRoutesByWorker.js b/modules/route/back/methods/route/getRoutesByWorker.js deleted file mode 100644 index 0a6f59816..000000000 --- a/modules/route/back/methods/route/getRoutesByWorker.js +++ /dev/null @@ -1,48 +0,0 @@ -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); - }; -}; diff --git a/modules/route/back/methods/route/specs/getByWorker.spec.js b/modules/route/back/methods/route/specs/getByWorker.spec.js new file mode 100644 index 000000000..52b8d6d87 --- /dev/null +++ b/modules/route/back/methods/route/specs/getByWorker.spec.js @@ -0,0 +1,39 @@ +const app = require('vn-loopback/server/server'); +const LoopBackContext = require('loopback-context'); + +fdescribe('route getByWorker()', () => { + const userId = 56; + const activeCtx = { + accessToken: {userId: userId}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + const ctx = {req: activeCtx}; + + beforeAll(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); + + it('should return routes assigned to the worker', async() => { + const result = await app.models.Route.getByWorker(ctx); + + // Aquí se verifica que el resultado contiene rutas asignadas al usuario + console.log(result); + + expect(result.every(route => route.workerFk === userId)).toBe(true); + }); + + it('should return all routes if user has canViewAllRoute permission', async() => { + // Simular que el usuario tiene permiso para ver todas las rutas + spyOn(app.models.ACL, 'checkAccessAcl').and.returnValue(Promise.resolve(true)); + + const result = await app.models.Route.getByWorker(ctx); + + expect(result.some(route => route.workerFk != userId)).toBe(true); + }); +}); diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js index 073c601fe..cbdd75679 100644 --- a/modules/route/back/models/route.js +++ b/modules/route/back/models/route.js @@ -14,10 +14,10 @@ module.exports = Self => { require('../methods/route/driverRouteEmail')(Self); require('../methods/route/sendSms')(Self); require('../methods/route/downloadZip')(Self); - require('../methods/route/getRoutesByWorker')(Self); require('../methods/route/cmr')(Self); require('../methods/route/getExternalCmrs')(Self); require('../methods/route/downloadCmrsZip')(Self); + require('../methods/route/getByWorker')(Self); Self.validate('kmStart', validateDistance, { message: 'Distance must be lesser than 1000' From f44424dbcfe92bc3bb5b5f3e42467ef8acfb6d2c Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 23 Nov 2023 09:44:47 +0100 Subject: [PATCH 3/4] test: refs #6028 test --- back/methods/collection/newCollection.js | 133 ------------------ .../collection/spec/newCollection.spec.js | 12 -- back/models/collection.js | 1 - .../00-getRoutesByWorker.sql | 6 + .../route/back/methods/route/getByWorker.js | 3 +- .../methods/route/specs/getByWorker.spec.js | 5 +- 6 files changed, 8 insertions(+), 152 deletions(-) delete mode 100644 back/methods/collection/newCollection.js delete mode 100644 back/methods/collection/spec/newCollection.spec.js rename db/changes/{234801 => 235001}/00-getRoutesByWorker.sql (71%) diff --git a/back/methods/collection/newCollection.js b/back/methods/collection/newCollection.js deleted file mode 100644 index 2be9f8b0e..000000000 --- a/back/methods/collection/newCollection.js +++ /dev/null @@ -1,133 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('newCollection', { - description: 'Make a new collection of tickets', - accessType: 'WRITE', - accepts: [{ - arg: 'collectionFk', - type: 'Number', - required: false, - description: 'The collection id' - }, { - arg: 'sectorFk', - type: 'Number', - required: true, - description: 'The sector of worker' - }, { - arg: 'vWagons', - type: 'Number', - required: true, - description: 'The number of wagons' - }], - returns: { - type: 'Object', - root: true - }, - http: { - path: `/newCollection`, - verb: 'POST' - } - }); - - Self.newCollection = async(ctx, collectionFk, sectorFk, vWagons) => { - let query = ''; - const userId = ctx.req.accessToken.userId; - - if (!collectionFk) { - query = `CALL vn.collectionTrain_newBeta(?,?,?)`; - const [result] = await Self.rawSql(query, [sectorFk, vWagons, userId], {userId}); - if (result.length == 0) - throw new Error(`No collections for today`); - - collectionFk = result[0].vCollectionFk; - } - - query = `CALL vn.collectionTicket_get(?)`; - const [tickets] = await Self.rawSql(query, [collectionFk], {userId}); - - query = `CALL vn.collectionSale_get(?)`; - const [sales] = await Self.rawSql(query, [collectionFk], {userId}); - - query = `CALL vn.collectionPlacement_get(?)`; - const [placements] = await Self.rawSql(query, [collectionFk], {userId}); - - query = `CALL vn.collectionSticker_print(?,?)`; - await Self.rawSql(query, [collectionFk, sectorFk], {userId}); - - return makeCollection(tickets, sales, placements, collectionFk); - }; - - /** - * Returns a collection json - * @param {*} tickets - Request tickets - * @param {*} sales - Request sales - * @param {*} placements - Request placements - * @param {*} collectionFk - Request placements - * @return {Object} Collection JSON - */ - async function makeCollection(tickets, sales, placements, collectionFk) { - let collection = []; - - for (let i = 0; i < tickets.length; i++) { - let ticket = {}; - ticket['ticketFk'] = tickets[i]['ticketFk']; - ticket['level'] = tickets[i]['level']; - ticket['agencyName'] = tickets[i]['agencyName']; - ticket['warehouseFk'] = tickets[i]['warehouseFk']; - ticket['salesPersonFk'] = tickets[i]['salesPersonFk']; - - let ticketSales = []; - - for (let x = 0; x < sales.length; x++) { - if (sales[x]['ticketFk'] == ticket['ticketFk']) { - let sale = {}; - sale['collectionFk'] = collectionFk; - sale['ticketFk'] = sales[x]['ticketFk']; - sale['saleFk'] = sales[x]['saleFk']; - sale['itemFk'] = sales[x]['itemFk']; - sale['quantity'] = sales[x]['quantity']; - if (sales[x]['quantityPicked'] != null) - sale['quantityPicked'] = sales[x]['quantityPicked']; - else - sale['quantityPicked'] = 0; - sale['longName'] = sales[x]['longName']; - sale['size'] = sales[x]['size']; - sale['color'] = sales[x]['color']; - sale['discount'] = sales[x]['discount']; - sale['price'] = sales[x]['price']; - sale['stems'] = sales[x]['stems']; - sale['category'] = sales[x]['category']; - sale['origin'] = sales[x]['origin']; - sale['clientFk'] = sales[x]['clientFk']; - sale['productor'] = sales[x]['productor']; - sale['reserved'] = sales[x]['reserved']; - sale['isPreviousPrepared'] = sales[x]['isPreviousPrepared']; - sale['isPrepared'] = sales[x]['isPrepared']; - sale['isControlled'] = sales[x]['isControlled']; - - let salePlacements = []; - - for (let z = 0; z < placements.length; z++) { - if (placements[z]['saleFk'] == sale['saleFk']) { - let placement = {}; - placement['saleFk'] = placements[z]['saleFk']; - placement['itemFk'] = placements[z]['itemFk']; - placement['placement'] = placements[z]['placement']; - placement['shelving'] = placements[z]['shelving']; - placement['created'] = placements[z]['created']; - placement['visible'] = placements[z]['visible']; - placement['order'] = placements[z]['order']; - placement['grouping'] = placements[z]['grouping']; - salePlacements.push(placement); - } - } - sale['placements'] = salePlacements; - ticketSales.push(sale); - } - } - ticket['sales'] = ticketSales; - collection.push(ticket); - } - - return collection; - } -}; diff --git a/back/methods/collection/spec/newCollection.spec.js b/back/methods/collection/spec/newCollection.spec.js deleted file mode 100644 index e729594d1..000000000 --- a/back/methods/collection/spec/newCollection.spec.js +++ /dev/null @@ -1,12 +0,0 @@ -const {models} = require('vn-loopback/server/server'); - -describe('newCollection()', () => { - it('should return a new collection', async() => { - pending('#3400 analizar que hacer con rutas de back collection'); - let ctx = {req: {accessToken: {userId: 1106}}}; - let response = await models.Collection.newCollection(ctx, 1, 1, 1); - - expect(response.length).toBeGreaterThan(0); - expect(response[0].ticketFk).toEqual(2); - }); -}); diff --git a/back/models/collection.js b/back/models/collection.js index bfa906af6..1c10d49fa 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -1,6 +1,5 @@ module.exports = Self => { require('../methods/collection/getCollection')(Self); - require('../methods/collection/newCollection')(Self); require('../methods/collection/getSectors')(Self); require('../methods/collection/setSaleQuantity')(Self); require('../methods/collection/previousLabel')(Self); diff --git a/db/changes/234801/00-getRoutesByWorker.sql b/db/changes/235001/00-getRoutesByWorker.sql similarity index 71% rename from db/changes/234801/00-getRoutesByWorker.sql rename to db/changes/235001/00-getRoutesByWorker.sql index bdc4a246e..00d6e658a 100644 --- a/db/changes/234801/00-getRoutesByWorker.sql +++ b/db/changes/235001/00-getRoutesByWorker.sql @@ -11,7 +11,13 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `pri ('Route', 'findOne', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Route', 'getRoutesByWorker', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Route', 'canViewAllRoute', 'READ', 'ALLOW', 'ROLE', 'deliveryBoss'), + ('Route', 'cmr', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Route', 'downloadCmrsZip', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Route', 'downloadZip', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Route', 'filter', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Route', 'getByWorker', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Route', 'getDeliveryPoint', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Route', 'getExternalCmrs', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Route', 'getSuggestedTickets', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'employee'), ('Route', 'guessPriority', 'WRITE', 'ALLOW', 'ROLE', 'employee'), diff --git a/modules/route/back/methods/route/getByWorker.js b/modules/route/back/methods/route/getByWorker.js index 2f8a286e6..7e70cb1f1 100644 --- a/modules/route/back/methods/route/getByWorker.js +++ b/modules/route/back/methods/route/getByWorker.js @@ -24,8 +24,7 @@ module.exports = Self => { const canViewAll = await models.ACL.checkAccessAcl(ctx, 'Route', 'canViewAllRoute', 'READ'); let filterGrant = {}; - console.log(userId); - console.log(canViewAll); + if (canViewAll) { const userConfig = await models.UserConfig.getUserConfig(ctx, myOptions); filterGrant = { diff --git a/modules/route/back/methods/route/specs/getByWorker.spec.js b/modules/route/back/methods/route/specs/getByWorker.spec.js index 52b8d6d87..f3103509a 100644 --- a/modules/route/back/methods/route/specs/getByWorker.spec.js +++ b/modules/route/back/methods/route/specs/getByWorker.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -fdescribe('route getByWorker()', () => { +describe('route getByWorker()', () => { const userId = 56; const activeCtx = { accessToken: {userId: userId}, @@ -22,9 +22,6 @@ fdescribe('route getByWorker()', () => { it('should return routes assigned to the worker', async() => { const result = await app.models.Route.getByWorker(ctx); - // Aquí se verifica que el resultado contiene rutas asignadas al usuario - console.log(result); - expect(result.every(route => route.workerFk === userId)).toBe(true); }); From 5b145a57e6991bf07c54c4f1126834028c592cc9 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 23 Nov 2023 11:29:53 +0100 Subject: [PATCH 4/4] error: refs 6028 test front quitado --- modules/route/front/tickets/index.spec.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js index 2c73048bd..fef4b8331 100644 --- a/modules/route/front/tickets/index.spec.js +++ b/modules/route/front/tickets/index.spec.js @@ -209,22 +209,6 @@ describe('Route', () => { }); }); - describe('guessPriority()', () => { - it('should perform a GET query then call both refresh and showSuccess methods', () => { - jest.spyOn(controller.$.model, 'refresh'); - jest.spyOn(controller.vnApp, 'showSuccess'); - controller.$params = {id: 99}; - - const url = `Routes/${controller.$params.id}/guessPriority/`; - $httpBackend.expectGET(url).respond('ok'); - controller.guessPriority(); - $httpBackend.flush(); - - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Order changed'); - expect(controller.$.model.refresh).toHaveBeenCalledWith(); - }); - }); - describe('onDrop()', () => { it('should call the insert method when dragging a ticket number', () => { jest.spyOn(controller, 'insert');