Bug #589 cambiar el estado desde ticket.sales no guarda el historico

This commit is contained in:
gerard 2018-08-21 07:39:01 +02:00
parent 2d6932fe49
commit ca523e634c
3 changed files with 17 additions and 15 deletions

View File

@ -1,4 +1,4 @@
<mg-ajax path="/ticket/api/TicketTrackings" options="vnPost"></mg-ajax>
<mg-ajax path="/ticket/api/TicketTrackings/changeState" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.ticket"

View File

@ -1,7 +1,7 @@
const UserError = require('vn-loopback/common/helpers').UserError;
module.exports = Self => {
Self.remoteMethod('changeState', {
Self.remoteMethodCtx('changeState', {
description: 'Change the state of a ticket',
accessType: 'WRITE',
accepts: [{
@ -21,11 +21,22 @@ module.exports = Self => {
}
});
Self.changeState = async params => {
Self.changeState = async(ctx, params) => {
let models = Self.app.models;
let isProduction;
let isEditable = await Self.app.models.Ticket.isEditable(params.ticketFk);
if (isEditable)
return await Self.app.models.TicketTracking.create(params);
throw new UserError(`You don't have enough privileges to change the state of this ticket`);
if (ctx.req.accessToken) {
let token = ctx.req.accessToken;
let currentUserId = token && token.userId;
isProduction = await models.Account.hasRole(currentUserId, 'Production');
let worker = await models.Worker.findOne({where: {userFk: currentUserId}});
params.workerFk = worker.id;
}
if (!isEditable && !isProduction)
throw new UserError(`You don't have enough privileges to change the state of this ticket`);
return await Self.app.models.TicketTracking.create(params);
};
};

View File

@ -2,13 +2,4 @@ module.exports = function(Self) {
require('../methods/ticket-tracking/changeState')(Self);
Self.validatesPresenceOf('stateFk', {message: 'State cannot be blank'});
Self.observe('before save', async function(ctx) {
let models = Self.app.models;
let token = ctx.options.accessToken;
let currentUserId = token && token.userId;
let worker = await models.Worker.findOne({where: {userFk: currentUserId}});
ctx.instance.workerFk = worker.id;
});
};