refactor(ticketTracking.create): refs #6366 unify Ticket.state ticketTracking.create i vn.ticket_setState
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
ad07c4ec97
commit
0a5e8e1902
|
@ -296,6 +296,7 @@
|
||||||
"Invalid NIF for VIES": "Invalid NIF for VIES",
|
"Invalid NIF for VIES": "Invalid NIF for VIES",
|
||||||
"Ticket does not exist": "Este ticket no existe",
|
"Ticket does not exist": "Este ticket no existe",
|
||||||
"Ticket is already signed": "Este ticket ya ha sido firmado",
|
"Ticket is already signed": "Este ticket ya ha sido firmado",
|
||||||
|
"The DELIVERED state does not exist": "El estado DELIVERED no existe",
|
||||||
"Authentication failed": "Autenticación fallida",
|
"Authentication failed": "Autenticación fallida",
|
||||||
"You can't use the same password": "No puedes usar la misma contraseña",
|
"You can't use the same password": "No puedes usar la misma contraseña",
|
||||||
"You can only add negative amounts in refund tickets": "Solo se puede añadir cantidades negativas en tickets abono",
|
"You can only add negative amounts in refund tickets": "Solo se puede añadir cantidades negativas en tickets abono",
|
||||||
|
|
|
@ -120,7 +120,7 @@ module.exports = Self => {
|
||||||
observationTypeFk: obsevationType.id
|
observationTypeFk: obsevationType.id
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
await models.TicketTracking.create({
|
await models.Ticket.state(ctx, {
|
||||||
ticketFk: newRefundTicket.id,
|
ticketFk: newRefundTicket.id,
|
||||||
stateFk: state.id,
|
stateFk: state.id,
|
||||||
workerFk: worker.id
|
workerFk: worker.id
|
||||||
|
|
|
@ -130,7 +130,19 @@ module.exports = Self => {
|
||||||
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
|
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
|
||||||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||||
await ticket.updateAttribute('isSigned', true, myOptions);
|
await ticket.updateAttribute('isSigned', true, myOptions);
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, 'DELIVERED'], myOptions);
|
|
||||||
|
const deliveryState = await models.State.find({
|
||||||
|
where: {
|
||||||
|
code: 'DELIVERED'
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
if (!deliveryState)
|
||||||
|
throw new UserError('The DELIVERED state does not exist');
|
||||||
|
|
||||||
|
await models.Ticket.state(ctx, {
|
||||||
|
ticketFk: ticketId,
|
||||||
|
stateFk: deliveryState.id
|
||||||
|
}, myOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
|
@ -45,9 +45,8 @@ describe('ticket state()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
activeCtx.accessToken.userId = salesPersonId;
|
activeCtx.accessToken.userId = salesPersonId;
|
||||||
const params = {ticketFk: 2, stateFk: 3};
|
|
||||||
|
|
||||||
await models.Ticket.state(ctx, params, options);
|
await models.Ticket.state(ctx, {ticketFk: 2, stateFk: 3}, options);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -67,9 +66,8 @@ describe('ticket state()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
activeCtx.accessToken.userId = employeeId;
|
activeCtx.accessToken.userId = employeeId;
|
||||||
const params = {ticketFk: 11, stateFk: 13};
|
|
||||||
|
|
||||||
await models.Ticket.state(ctx, params, options);
|
await models.Ticket.state(ctx, {ticketFk: 11, stateFk: 13}, options);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -94,10 +92,10 @@ describe('ticket state()', () => {
|
||||||
|
|
||||||
const ticketTracking = await models.Ticket.state(ctx, params, options);
|
const ticketTracking = await models.Ticket.state(ctx, params, options);
|
||||||
|
|
||||||
expect(ticketTracking.__data.ticketFk).toBe(params.ticketFk);
|
expect(ticketTracking.ticketFk).toBe(params.ticketFk);
|
||||||
expect(ticketTracking.__data.stateFk).toBe(params.stateFk);
|
expect(ticketTracking.stateFk).toBe(params.stateFk);
|
||||||
expect(ticketTracking.__data.workerFk).toBe(49);
|
expect(ticketTracking.workerFk).toBe(49);
|
||||||
expect(ticketTracking.__data.id).toBeDefined();
|
expect(ticketTracking.id).toBeDefined();
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -119,11 +117,10 @@ describe('ticket state()', () => {
|
||||||
const params = {ticketFk: ticket.id, stateFk: assignedState.id, workerFk: 1};
|
const params = {ticketFk: ticket.id, stateFk: assignedState.id, workerFk: 1};
|
||||||
const res = await models.Ticket.state(ctx, params, options);
|
const res = await models.Ticket.state(ctx, params, options);
|
||||||
|
|
||||||
expect(res.__data.ticketFk).toBe(params.ticketFk);
|
expect(res.ticketFk).toBe(params.ticketFk);
|
||||||
expect(res.__data.stateFk).toBe(params.stateFk);
|
expect(res.stateFk).toBe(params.stateFk);
|
||||||
expect(res.__data.workerFk).toBe(params.workerFk);
|
expect(res.workerFk).toBe(params.workerFk);
|
||||||
expect(res.__data.workerFk).toBe(1);
|
expect(res.id).toBeDefined();
|
||||||
expect(res.__data.id).toBeDefined();
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -37,18 +37,14 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userId = ctx.req.accessToken.userId;
|
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.code) {
|
if (params.stateFk) {
|
||||||
const state = await models.State.findOne({
|
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
||||||
where: {code: params.code},
|
params.code = code;
|
||||||
fields: ['id']
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
params.stateFk = state.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.workerFk) {
|
if (!params.workerFk) {
|
||||||
|
@ -68,12 +64,19 @@ module.exports = Self => {
|
||||||
oldStateAllowed = await models.State.isEditable(ctx, ticketState.stateFk, myOptions);
|
oldStateAllowed = await models.State.isEditable(ctx, ticketState.stateFk, myOptions);
|
||||||
const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions);
|
const newStateAllowed = await models.State.isEditable(ctx, params.stateFk, myOptions);
|
||||||
|
|
||||||
const isAllowed = (!ticketState || oldStateAllowed == true) && newStateAllowed == true;
|
if (!((!ticketState || oldStateAllowed == true) && newStateAllowed == true))
|
||||||
|
|
||||||
if (!isAllowed)
|
|
||||||
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
||||||
|
|
||||||
const ticketTracking = await models.TicketTracking.create(params, myOptions);
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions);
|
||||||
|
|
||||||
|
const ticketTracking = await models.TicketTracking.findOne({
|
||||||
|
where: {ticketFk: params.ticketFk},
|
||||||
|
order: 'id DESC',
|
||||||
|
limit: 1
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (params.workerFk)
|
||||||
|
await ticketTracking.updateAttribute('workerFk', params.workerFk, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
for (ticket of ticketList) {
|
for (ticket of ticketList) {
|
||||||
if (ticket.ticketState().alertLevel == 0) {
|
if (ticket.ticketState().alertLevel == 0) {
|
||||||
promises.push(models.TicketTracking.create({
|
promises.push(models.Ticket.state(ctx, {
|
||||||
ticketFk: ticket.id,
|
ticketFk: ticket.id,
|
||||||
stateFk: fixingState.id,
|
stateFk: fixingState.id,
|
||||||
workerFk: worker.id
|
workerFk: worker.id
|
||||||
|
|
Loading…
Reference in New Issue