refactor(ticketTracking.create): refs #6366 unify Ticket.state ticketTracking.create i vn.ticket_setState #1838
|
@ -136,8 +136,6 @@ module.exports = Self => {
|
||||||
code: 'DELIVERED'
|
code: 'DELIVERED'
|
||||||
}
|
}
|
||||||
}, options);
|
}, options);
|
||||||
if (!deliveryState)
|
|
||||||
throw new UserError('The DELIVERED state does not exist');
|
|
||||||
|
|
||||||
pablone marked this conversation as resolved
|
|||||||
await models.Ticket.state(ctx, {
|
await models.Ticket.state(ctx, {
|
||||||
ticketFk: ticketId,
|
ticketFk: ticketId,
|
||||||
|
|
|
@ -58,13 +58,10 @@ module.exports = Self => {
|
||||||
fields: ['stateFk']
|
fields: ['stateFk']
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const oldStateAllowed = ticketState ?
|
const oldStateAllowed = ticketState && await models.State.isEditable(ctx, ticketState.stateFk, myOptions);
|
||||||
pablone marked this conversation as resolved
Outdated
alexm
commented
const oldStateAllowed = ticketState && await models.State.isEditable(ctx, ticketState.stateFk, myOptions); const oldStateAllowed = ticketState && await models.State.isEditable(ctx, ticketState.stateFk, myOptions);
|
|||||||
await models.State.isEditable(ctx, ticketState.stateFk, myOptions) :
|
|
||||||
false;
|
|
||||||
|
|
||||||
const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions);
|
const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions);
|
||||||
|
|
||||||
if (!((!ticketState || oldStateAllowed == true) && newStateAllowed == true))
|
if ((ticketState && !oldStateAllowed) || !newStateAllowed)
|
||||||
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
||||||
|
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions);
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions);
|
||||||
pablone marked this conversation as resolved
alexm
commented
Crec que queda mes simple com: Crec que queda mes simple com:
if ((ticketState && !oldStateAllowed) || !newStateAllowed)
|
|||||||
|
|
Loading…
Reference in New Issue
Este if no el acabe de vore.