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",
|
"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",
|
"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}}",
|
"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 => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('saveSign', {
|
Self.remoteMethodCtx('saveSign', {
|
||||||
description: 'Save sign',
|
description: 'Save sign',
|
||||||
|
@ -46,7 +48,6 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setLocation(ticketId) {
|
async function setLocation(ticketId) {
|
||||||
if (args.signedTime) {
|
|
||||||
await models.Delivery.create({
|
await models.Delivery.create({
|
||||||
ticketFk: ticketId,
|
ticketFk: ticketId,
|
||||||
longitude: args.location.Longitude,
|
longitude: args.location.Longitude,
|
||||||
|
@ -54,13 +55,10 @@ module.exports = Self => {
|
||||||
dated: args.signedTime || new Date()
|
dated: args.signedTime || new Date()
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async function gestDocExists(ticketId) {
|
async function gestDocExists(ticketId) {
|
||||||
const ticketDms = await models.TicketDms.findOne({
|
const ticketDms = await models.TicketDms.findOne({
|
||||||
where: {
|
where: {ticketFk: ticketId},
|
||||||
ticketFk: ticketId
|
|
||||||
},
|
|
||||||
fields: ['dmsFk']
|
fields: ['dmsFk']
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
@ -120,12 +118,13 @@ module.exports = Self => {
|
||||||
if (args.location) setLocation(args.tickets[i]);
|
if (args.location) setLocation(args.tickets[i]);
|
||||||
await createGestDoc(args.tickets[i]);
|
await createGestDoc(args.tickets[i]);
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [args.tickets[i], 'DELIVERED'], myOptions);
|
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();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return 'Signs uploaded correctly';
|
return 'Signs uploaded successfully';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -1,57 +1,32 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
fdescribe('TicketDms saveSign()', () => {
|
describe('TicketDms saveSign()', () => {
|
||||||
const FormData = require('form-data');
|
const FormData = require('form-data');
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
let ctx = {req: {
|
let ctx = {req: {
|
||||||
accessToken: {userId: 9},
|
accessToken: {userId: 9},
|
||||||
headers: {
|
headers: {
|
||||||
...data.getHeaders()
|
...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 tx = await models.TicketDms.beginTransaction({});
|
||||||
const ticketWithOkState = 12;
|
const ticketWithOkState = 12;
|
||||||
|
let error;
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
ctx.args = {tickets: [ticketWithOkState]};
|
ctx.args = {tickets: [ticketWithOkState]};
|
||||||
|
|
||||||
await models.TicketDms.saveSign(ctx, options);
|
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();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
it(`should save sign if the ticket's alert level is greater than 2`, async() => {
|
expect(error).toBeDefined();
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue