refactor(state): refs #6366 unifyTicketChangeState
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
f7ec64f3c1
commit
ccf5387e04
|
@ -49,7 +49,7 @@ module.exports = Self => {
|
||||||
for (const id of ticketIds) {
|
for (const id of ticketIds) {
|
||||||
const promise = await models.Ticket.state(ctx, {
|
const promise = await models.Ticket.state(ctx, {
|
||||||
stateFk: state.id,
|
stateFk: state.id,
|
||||||
workerFk: worker.id,
|
userFk: worker.id,
|
||||||
ticketFk: id
|
ticketFk: id
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
promises.push(promise);
|
promises.push(promise);
|
||||||
|
|
|
@ -7,7 +7,6 @@ module.exports = Self => {
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'data',
|
arg: 'data',
|
||||||
description: 'Model instance data',
|
|
||||||
type: 'Object',
|
type: 'Object',
|
||||||
required: true,
|
required: true,
|
||||||
http: {source: 'body'}
|
http: {source: 'body'}
|
||||||
|
@ -37,21 +36,21 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {userId} = ctx.req.accessToken;
|
|
||||||
|
|
||||||
if (!params.stateFk && !params.code)
|
if (!params.stateFk && !params.code)
|
||||||
throw new UserError('State cannot be blank');
|
throw new UserError('State cannot be blank');
|
||||||
|
|
||||||
if (params.stateFk) {
|
if (params.stateFk) {
|
||||||
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
||||||
params.code = code;
|
params.code = code;
|
||||||
|
} else {
|
||||||
|
const {id} = await models.State.findOne({where: {code: params.code}}, myOptions);
|
||||||
|
params.stateFk = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.userFk) {
|
if (!params.userFk) {
|
||||||
const worker = await models.Worker.findOne({
|
const worker = await models.Worker.findOne({
|
||||||
where: {id: userId}
|
where: {id: ctx.req.accessToken.userId}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
params.userFk = worker.id;
|
params.userFk = worker.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +58,10 @@ module.exports = Self => {
|
||||||
fields: ['stateFk']
|
fields: ['stateFk']
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
let oldStateAllowed;
|
const oldStateAllowed = ticketState ?
|
||||||
if (ticketState)
|
await models.State.isEditable(ctx, ticketState.stateFk, myOptions) :
|
||||||
oldStateAllowed = 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 == true) && newStateAllowed == true))
|
||||||
|
@ -75,8 +75,7 @@ module.exports = Self => {
|
||||||
limit: 1
|
limit: 1
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (params.workerFk)
|
await ticketTracking.updateAttribute('userFk', params.userFk, myOptions);
|
||||||
await ticketTracking.updateAttribute('workerFk', params.workerFk, myOptions);
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue