refactor(state): refs #6366 unifyTicketChangeState
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Pablo Natek 2023-12-29 12:44:24 +01:00
parent f7ec64f3c1
commit ccf5387e04
2 changed files with 10 additions and 11 deletions

View File

@ -49,7 +49,7 @@ module.exports = Self => {
for (const id of ticketIds) {
const promise = await models.Ticket.state(ctx, {
stateFk: state.id,
workerFk: worker.id,
userFk: worker.id,
ticketFk: id
}, myOptions);
promises.push(promise);

View File

@ -7,7 +7,6 @@ module.exports = Self => {
accepts: [
{
arg: 'data',
description: 'Model instance data',
type: 'Object',
required: true,
http: {source: 'body'}
@ -37,21 +36,21 @@ module.exports = Self => {
}
try {
const {userId} = ctx.req.accessToken;
if (!params.stateFk && !params.code)
throw new UserError('State cannot be blank');
if (params.stateFk) {
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
params.code = code;
} else {
const {id} = await models.State.findOne({where: {code: params.code}}, myOptions);
params.stateFk = id;
}
if (!params.userFk) {
const worker = await models.Worker.findOne({
where: {id: userId}
where: {id: ctx.req.accessToken.userId}
}, myOptions);
params.userFk = worker.id;
}
@ -59,9 +58,10 @@ module.exports = Self => {
fields: ['stateFk']
}, myOptions);
let oldStateAllowed;
if (ticketState)
oldStateAllowed = await models.State.isEditable(ctx, ticketState.stateFk, myOptions);
const oldStateAllowed = ticketState ?
await models.State.isEditable(ctx, ticketState.stateFk, myOptions) :
false;
const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions);
if (!((!ticketState || oldStateAllowed == true) && newStateAllowed == true))
@ -75,8 +75,7 @@ module.exports = Self => {
limit: 1
}, myOptions);
if (params.workerFk)
await ticketTracking.updateAttribute('workerFk', params.workerFk, myOptions);
await ticketTracking.updateAttribute('userFk', params.userFk, myOptions);
if (tx) await tx.commit();