Merge branch '2088-ticket_datosBasicos' of verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
ba01be566e
|
@ -1,4 +1,5 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
const diff = require('object-diff');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('componentUpdate', {
|
Self.remoteMethodCtx('componentUpdate', {
|
||||||
|
@ -11,32 +12,32 @@ module.exports = Self => {
|
||||||
description: 'The ticket id',
|
description: 'The ticket id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
}, {
|
}, {
|
||||||
arg: 'clientId',
|
arg: 'clientFk',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
description: 'The client id',
|
description: 'The client id',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
}, {
|
||||||
arg: 'agencyModeId',
|
arg: 'agencyModeFk',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
description: 'The agencyMode id',
|
description: 'The agencyMode id',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
}, {
|
||||||
arg: 'addressId',
|
arg: 'addressFk',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
description: 'The address id',
|
description: 'The address id',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
}, {
|
||||||
arg: 'zoneId',
|
arg: 'zoneFk',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
description: 'The zone id',
|
description: 'The zone id',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
}, {
|
||||||
arg: 'warehouseId',
|
arg: 'warehouseFk',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
description: 'The warehouse id',
|
description: 'The warehouse id',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
}, {
|
||||||
arg: 'companyId',
|
arg: 'companyFk',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
description: 'The company id',
|
description: 'The company id',
|
||||||
required: true
|
required: true
|
||||||
|
@ -71,8 +72,8 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.componentUpdate = async(ctx, id, clientId, agencyModeId, addressId, zoneId, warehouseId,
|
Self.componentUpdate = async(ctx, id, clientFk, agencyModeFk, addressFk, zoneFk, warehouseFk,
|
||||||
companyId, shipped, landed, isDeleted, option) => {
|
companyFk, shipped, landed, isDeleted, option) => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const isEditable = await models.Ticket.isEditable(ctx, id);
|
const isEditable = await models.Ticket.isEditable(ctx, id);
|
||||||
|
@ -82,29 +83,49 @@ module.exports = Self => {
|
||||||
|
|
||||||
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
|
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
|
||||||
if (!isProductionBoss) {
|
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`);
|
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
|
// Force unroute
|
||||||
const hasToBeUnrouted = true;
|
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 query = 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
let res = await Self.rawSql(query, [
|
let res = await Self.rawSql(query, [
|
||||||
id,
|
id,
|
||||||
clientId,
|
clientFk,
|
||||||
agencyModeId,
|
agencyModeFk,
|
||||||
addressId,
|
addressFk,
|
||||||
zoneId,
|
zoneFk,
|
||||||
warehouseId,
|
warehouseFk,
|
||||||
companyId,
|
companyFk,
|
||||||
shipped,
|
shipped,
|
||||||
landed,
|
landed,
|
||||||
isDeleted,
|
isDeleted,
|
||||||
hasToBeUnrouted,
|
hasToBeUnrouted,
|
||||||
option
|
option
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
await models.TicketLog.create(logRecord);
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,7 +39,10 @@ describe('ticket componentUpdate()', () => {
|
||||||
const landed = tomorrow;
|
const landed = tomorrow;
|
||||||
const option = 1;
|
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,
|
await app.models.Ticket.componentUpdate(ctx, ticketId, clientId, agencyModeId, addressId,
|
||||||
zoneId, warehouseId, companyId, shipped, landed, isDeleted, option);
|
zoneId, warehouseId, companyId, shipped, landed, isDeleted, option);
|
||||||
|
@ -66,7 +69,11 @@ describe('ticket componentUpdate()', () => {
|
||||||
const landed = tomorrow;
|
const landed = tomorrow;
|
||||||
const option = 1;
|
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,
|
await app.models.Ticket.componentUpdate(ctx, ticketId, clientId, agencyModeId, addressId,
|
||||||
zoneId, warehouseId, companyId, shipped, landed, isDeleted, option);
|
zoneId, warehouseId, companyId, shipped, landed, isDeleted, option);
|
||||||
|
|
||||||
|
|
|
@ -75,12 +75,12 @@ class Controller {
|
||||||
|
|
||||||
let query = `tickets/${this.ticket.id}/componentUpdate`;
|
let query = `tickets/${this.ticket.id}/componentUpdate`;
|
||||||
let params = {
|
let params = {
|
||||||
clientId: this.ticket.clientFk,
|
clientFk: this.ticket.clientFk,
|
||||||
agencyModeId: this.ticket.agencyModeFk,
|
agencyModeFk: this.ticket.agencyModeFk,
|
||||||
addressId: this.ticket.addressFk,
|
addressFk: this.ticket.addressFk,
|
||||||
zoneId: this.ticket.zoneFk,
|
zoneFk: this.ticket.zoneFk,
|
||||||
warehouseId: this.ticket.warehouseFk,
|
warehouseFk: this.ticket.warehouseFk,
|
||||||
companyId: this.ticket.companyFk,
|
companyFk: this.ticket.companyFk,
|
||||||
shipped: this.ticket.shipped,
|
shipped: this.ticket.shipped,
|
||||||
landed: this.ticket.landed,
|
landed: this.ticket.landed,
|
||||||
isDeleted: this.ticket.isDeleted,
|
isDeleted: this.ticket.isDeleted,
|
||||||
|
|
Loading…
Reference in New Issue