refs #4632 added userError
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
423ae85212
commit
7c3c3a2d66
|
@ -266,5 +266,6 @@
|
|||
"There is no assigned email for this client": "No hay correo asignado para este cliente",
|
||||
"This locker has already been assigned": "Esta taquilla ya ha sido asignada",
|
||||
"Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº {{id}}",
|
||||
"Not exist this branch": "La rama no existe"
|
||||
"Not exist this branch": "La rama no existe",
|
||||
"This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado"
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('saveSign', {
|
||||
description: 'Save sign',
|
||||
|
@ -46,7 +48,6 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
async function setLocation(ticketId) {
|
||||
if (args.signedTime) {
|
||||
await models.Delivery.create({
|
||||
ticketFk: ticketId,
|
||||
longitude: args.location.Longitude,
|
||||
|
@ -54,13 +55,10 @@ module.exports = Self => {
|
|||
dated: args.signedTime || new Date()
|
||||
}, myOptions);
|
||||
}
|
||||
}
|
||||
|
||||
async function gestDocExists(ticketId) {
|
||||
const ticketDms = await models.TicketDms.findOne({
|
||||
where: {
|
||||
ticketFk: ticketId
|
||||
},
|
||||
where: {ticketFk: ticketId},
|
||||
fields: ['dmsFk']
|
||||
}, myOptions);
|
||||
|
||||
|
@ -120,12 +118,13 @@ module.exports = Self => {
|
|||
if (args.location) setLocation(args.tickets[i]);
|
||||
await createGestDoc(args.tickets[i]);
|
||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [args.tickets[i], 'DELIVERED'], myOptions);
|
||||
}
|
||||
} else if (ticketState.alertLevel < 2)
|
||||
throw new UserError('This ticket cannot be signed because it has not been boxed');
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return 'Signs uploaded correctly';
|
||||
return 'Signs uploaded successfully';
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -1,57 +1,32 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
fdescribe('TicketDms saveSign()', () => {
|
||||
describe('TicketDms saveSign()', () => {
|
||||
const FormData = require('form-data');
|
||||
const data = new FormData();
|
||||
let ctx = {req: {
|
||||
accessToken: {userId: 9},
|
||||
headers: {
|
||||
...data.getHeaders()
|
||||
},
|
||||
on: (param, cb) => {}
|
||||
}
|
||||
|
||||
}};
|
||||
|
||||
it(`should not save sign if the ticket's alert level is lower than 2`, async() => {
|
||||
it(`should throw error if the ticket's alert level is lower than 2`, async() => {
|
||||
const tx = await models.TicketDms.beginTransaction({});
|
||||
const ticketWithOkState = 12;
|
||||
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
ctx.args = {tickets: [ticketWithOkState]};
|
||||
|
||||
await models.TicketDms.saveSign(ctx, options);
|
||||
const ticket = await models.Ticket.findById(ticketWithOkState, {fields: ['isSigned']}, options);
|
||||
const ticketDms = await models.TicketDms.findOne({where: {ticketFk: ticketWithOkState}}, options);
|
||||
|
||||
expect(ticket.isSigned).toEqual(false);
|
||||
expect(ticketDms).toEqual(null);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it(`should save sign if the ticket's alert level is greater than 2`, async() => {
|
||||
const tx = await models.TicketDms.beginTransaction({});
|
||||
const ticketWithPackedState = 7;
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
ctx.args = {tickets: [ticketWithPackedState]};
|
||||
|
||||
await models.TicketDms.saveSign(ctx, options);
|
||||
const ticket = await models.Ticket.findById(ticketWithPackedState, {fields: ['isSigned']}, options);
|
||||
const ticketDms = await models.TicketDms.findOne({where: {ticketFk: ticketWithPackedState}}, options);
|
||||
|
||||
expect(ticket.isSigned).toEqual(true);
|
||||
expect(ticketDms).toBeDefined();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue