Merge branch '2088-ticket_datosBasicos' of verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-03-16 08:54:57 +00:00 committed by Gitea
commit ba01be566e
3 changed files with 53 additions and 25 deletions

View File

@ -1,4 +1,5 @@
const UserError = require('vn-loopback/util/user-error');
const diff = require('object-diff');
module.exports = Self => {
Self.remoteMethodCtx('componentUpdate', {
@ -11,32 +12,32 @@ module.exports = Self => {
description: 'The ticket id',
http: {source: 'path'}
}, {
arg: 'clientId',
arg: 'clientFk',
type: 'Number',
description: 'The client id',
required: true
}, {
arg: 'agencyModeId',
arg: 'agencyModeFk',
type: 'Number',
description: 'The agencyMode id',
required: true
}, {
arg: 'addressId',
arg: 'addressFk',
type: 'Number',
description: 'The address id',
required: true
}, {
arg: 'zoneId',
arg: 'zoneFk',
type: 'Number',
description: 'The zone id',
required: true
}, {
arg: 'warehouseId',
arg: 'warehouseFk',
type: 'Number',
description: 'The warehouse id',
required: true
}, {
arg: 'companyId',
arg: 'companyFk',
type: 'Number',
description: 'The company id',
required: true
@ -71,8 +72,8 @@ module.exports = Self => {
}
});
Self.componentUpdate = async(ctx, id, clientId, agencyModeId, addressId, zoneId, warehouseId,
companyId, shipped, landed, isDeleted, option) => {
Self.componentUpdate = async(ctx, id, clientFk, agencyModeFk, addressFk, zoneFk, warehouseFk,
companyFk, shipped, landed, isDeleted, option) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const isEditable = await models.Ticket.isEditable(ctx, id);
@ -82,29 +83,49 @@ module.exports = Self => {
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
if (!isProductionBoss) {
const zoneShipped = await models.Agency.getShipped(landed, addressId, agencyModeId, warehouseId);
const zoneShipped = await models.Agency.getShipped(landed, addressFk, agencyModeFk, warehouseFk);
if (!zoneShipped || zoneShipped.zoneFk != zoneId)
if (!zoneShipped || zoneShipped.zoneFk != zoneFk)
throw new UserError(`You don't have privileges to change the zone`);
}
const originalTicket = await models.Ticket.findById(id, {fields:
['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk',
'warehouseFk', 'companyFk', 'shipped', 'landed', 'isDeleted']
});
const updatedTicket = Object.assign({}, ctx.args);
delete updatedTicket.ctx;
delete updatedTicket.option;
// Force unroute
const hasToBeUnrouted = true;
const propertiesChange = diff(originalTicket, updatedTicket);
let logRecord = {
originFk: id,
userFk: userId,
action: 'update',
changedModel: 'Ticket',
changedModelId: id,
oldInstance: originalTicket,
newInstance: propertiesChange
};
let query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
let res = await Self.rawSql(query, [
id,
clientId,
agencyModeId,
addressId,
zoneId,
warehouseId,
companyId,
clientFk,
agencyModeFk,
addressFk,
zoneFk,
warehouseFk,
companyFk,
shipped,
landed,
isDeleted,
hasToBeUnrouted,
option
]);
await models.TicketLog.create(logRecord);
return res;
};
};

View File

@ -39,7 +39,10 @@ describe('ticket componentUpdate()', () => {
const landed = tomorrow;
const option = 1;
let ctx = {req: {accessToken: {userId: 101}}};
let ctx = {
args: {clientFk: 102,
agencyModeFk: 8},
req: {accessToken: {userId: 101}}};
await app.models.Ticket.componentUpdate(ctx, ticketId, clientId, agencyModeId, addressId,
zoneId, warehouseId, companyId, shipped, landed, isDeleted, option);
@ -66,7 +69,11 @@ describe('ticket componentUpdate()', () => {
const landed = tomorrow;
const option = 1;
let ctx = {req: {accessToken: {userId: 101}}};
let ctx = {
args: {clientFk: 102,
agencyModeFk: 7},
req: {accessToken: {userId: 101}}};
await app.models.Ticket.componentUpdate(ctx, ticketId, clientId, agencyModeId, addressId,
zoneId, warehouseId, companyId, shipped, landed, isDeleted, option);

View File

@ -75,12 +75,12 @@ class Controller {
let query = `tickets/${this.ticket.id}/componentUpdate`;
let params = {
clientId: this.ticket.clientFk,
agencyModeId: this.ticket.agencyModeFk,
addressId: this.ticket.addressFk,
zoneId: this.ticket.zoneFk,
warehouseId: this.ticket.warehouseFk,
companyId: this.ticket.companyFk,
clientFk: this.ticket.clientFk,
agencyModeFk: this.ticket.agencyModeFk,
addressFk: this.ticket.addressFk,
zoneFk: this.ticket.zoneFk,
warehouseFk: this.ticket.warehouseFk,
companyFk: this.ticket.companyFk,
shipped: this.ticket.shipped,
landed: this.ticket.landed,
isDeleted: this.ticket.isDeleted,