From 2ce442a022f292bbb4eac5694b8ff28eac3e7604 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 25 Jun 2019 11:17:58 +0200 Subject: [PATCH] #1555 ticket.lines transer to a new ticket --- front/core/components/td-editable/index.js | 1 - loopback/locale/es.json | 3 ++- modules/ticket/back/methods/sale/moveToTicket.js | 3 +++ .../back/methods/sale/specs/moveToTicket.spec.js | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/front/core/components/td-editable/index.js b/front/core/components/td-editable/index.js index ebf214564..37a6d30ab 100644 --- a/front/core/components/td-editable/index.js +++ b/front/core/components/td-editable/index.js @@ -1,6 +1,5 @@ import ngModule from '../../module'; import Component from '../../lib/component'; -import {focus} from '../../directives/focus'; import './style.scss'; export default class Controller extends Component { diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 6df1cb074..bc1bfe3aa 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -91,5 +91,6 @@ "NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada", "This item doesn't exists": "El artículo no existe", "NOT_ZONE_WITH_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada", - "Extension format is invalid": "El formato de la extensión es inválido" + "Extension format is invalid": "El formato de la extensión es inválido", + "Invalid parameters to create a new ticket": "Parámetros inválidos para crear un nuevo ticket" } \ No newline at end of file diff --git a/modules/ticket/back/methods/sale/moveToTicket.js b/modules/ticket/back/methods/sale/moveToTicket.js index c97225301..149989727 100644 --- a/modules/ticket/back/methods/sale/moveToTicket.js +++ b/modules/ticket/back/methods/sale/moveToTicket.js @@ -39,6 +39,9 @@ module.exports = Self => { if (!params.receiverTicket.id) { let travelDates = await models.Agency.getFirstShipped(params.currentTicket); + + if (!travelDates) + throw new UserError(`Invalid parameters to create a new ticket`); let shipped = new Date(travelDates.shipped); let landed = new Date(travelDates.landed); diff --git a/modules/ticket/back/methods/sale/specs/moveToTicket.spec.js b/modules/ticket/back/methods/sale/specs/moveToTicket.spec.js index cbf35d09c..8380ebb13 100644 --- a/modules/ticket/back/methods/sale/specs/moveToTicket.spec.js +++ b/modules/ticket/back/methods/sale/specs/moveToTicket.spec.js @@ -38,6 +38,21 @@ describe('sale moveToTicket()', () => { expect(error).toBeDefined(); }); + it('should throw an error when attempting to create a new ticket without delivery dates', async() => { + const ctx = {req: {accessToken: {userId: 101}}}; + let error; + + const params = {currentTicket: {currentTicketId: 18}, receiverTicket: {id: undefined}}; + + await app.models.Sale.moveToTicket(ctx, params) + .catch(response => { + expect(response.message).toEqual(`Invalid parameters to create a new ticket`); + error = response; + }); + + expect(error).toBeDefined(); + }); + it('should transfer the sales from one ticket to a new one', async() => { const ctx = {req: {accessToken: {userId: 101}}}; let currentTicket = await app.models.Ticket.findById(11);