This commit is contained in:
parent
5b289ec083
commit
f44424dbcf
|
@ -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;
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -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);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,6 +1,5 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/collection/getCollection')(Self);
|
require('../methods/collection/getCollection')(Self);
|
||||||
require('../methods/collection/newCollection')(Self);
|
|
||||||
require('../methods/collection/getSectors')(Self);
|
require('../methods/collection/getSectors')(Self);
|
||||||
require('../methods/collection/setSaleQuantity')(Self);
|
require('../methods/collection/setSaleQuantity')(Self);
|
||||||
require('../methods/collection/previousLabel')(Self);
|
require('../methods/collection/previousLabel')(Self);
|
||||||
|
|
|
@ -11,7 +11,13 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `pri
|
||||||
('Route', 'findOne', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
('Route', 'findOne', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
('Route', 'getRoutesByWorker', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
('Route', 'getRoutesByWorker', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
('Route', 'canViewAllRoute', 'READ', 'ALLOW', 'ROLE', 'deliveryBoss'),
|
('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', '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', 'getSuggestedTickets', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
('Route', 'guessPriority', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
('Route', 'guessPriority', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
|
@ -24,8 +24,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
const canViewAll = await models.ACL.checkAccessAcl(ctx, 'Route', 'canViewAllRoute', 'READ');
|
const canViewAll = await models.ACL.checkAccessAcl(ctx, 'Route', 'canViewAllRoute', 'READ');
|
||||||
let filterGrant = {};
|
let filterGrant = {};
|
||||||
console.log(userId);
|
|
||||||
console.log(canViewAll);
|
|
||||||
if (canViewAll) {
|
if (canViewAll) {
|
||||||
const userConfig = await models.UserConfig.getUserConfig(ctx, myOptions);
|
const userConfig = await models.UserConfig.getUserConfig(ctx, myOptions);
|
||||||
filterGrant = {
|
filterGrant = {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
fdescribe('route getByWorker()', () => {
|
describe('route getByWorker()', () => {
|
||||||
const userId = 56;
|
const userId = 56;
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
accessToken: {userId: userId},
|
accessToken: {userId: userId},
|
||||||
|
@ -22,9 +22,6 @@ fdescribe('route getByWorker()', () => {
|
||||||
it('should return routes assigned to the worker', async() => {
|
it('should return routes assigned to the worker', async() => {
|
||||||
const result = await app.models.Route.getByWorker(ctx);
|
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);
|
expect(result.every(route => route.workerFk === userId)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue