diff --git a/db/changes/10002-lent/00-printQueue.sql b/db/changes/10002-lent/00-printQueue.sql index d2493458b..f4fd5b569 100644 --- a/db/changes/10002-lent/00-printQueue.sql +++ b/db/changes/10002-lent/00-printQueue.sql @@ -7,10 +7,6 @@ ALTER TABLE `vn2008`.`Colas` CHANGE COLUMN `Id_Impresora` `Id_Impresora` TINYINT(3) UNSIGNED NULL DEFAULT NULL , CHANGE COLUMN `Id_Prioridad` `Id_Prioridad` TINYINT(3) UNSIGNED NULL DEFAULT NULL ; ALTER TABLE `vn2008`.`Colas` -ADD CONSTRAINT `Colas_ibfk_4` - FOREIGN KEY (`Id_Impresora`) - REFERENCES `vn2008`.`Impresoras` (`Id_Impresora`) - ON UPDATE CASCADE, ADD CONSTRAINT `Colas_ibfk_3` FOREIGN KEY (`Id_Prioridad`) REFERENCES `vn2008`.`Prioridades` (`Id_Prioridad`) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 73906c9a1..faf552caf 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -3,10 +3,6 @@ ALTER TABLE `vn`.`itemTaxCountry` AUTO_INCREMENT = 1; ALTER TABLE `vn2008`.`Consignatarios` AUTO_INCREMENT = 1; -INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) - VALUES - ('1', '6'); - INSERT INTO `account`.`mailConfig` (`id`, `domain`) VALUES ('1', 'verdnatura.es'); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 96d3ad070..b067b6121 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -81,5 +81,6 @@ "This ticket can't be invoiced": "Este ticket no puede ser facturado", "That item is not available on that day": "El item no esta disponible para esa fecha", "That item doesn't exists": "That item doesn't exists", - "You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado" + "You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado", + "This ticket can not be modified": "Este ticket no puede ser modificado" } \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/specs/updateEditableTicket.spec.js b/modules/ticket/back/methods/ticket/specs/updateEditableTicket.spec.js new file mode 100644 index 000000000..e792b925f --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/updateEditableTicket.spec.js @@ -0,0 +1,34 @@ +const app = require('vn-loopback/server/server'); + +describe('ticket updateEditableTicket()', () => { + const validTicketId = 12; + const invalidTicketId = 1; + const data = {addressFk: 1}; + const originalData = {addressFk: 121}; + + afterAll(async done => { + await app.models.Ticket.updateEditableTicket(validTicketId, originalData); + + done(); + }); + + it('should throw an error if the ticket is not editable', async() => { + let error; + await app.models.Ticket.updateEditableTicket(invalidTicketId, data).catch(e => { + error = e; + }).finally(() => { + expect(error.message).toEqual('This ticket can not be modified'); + }); + + expect(error).toBeDefined(); + }); + + + it('should edit the ticket address', async() => { + await app.models.Ticket.updateEditableTicket(validTicketId, data); + + let updatedTicket = await app.models.Ticket.findById(validTicketId); + + expect(updatedTicket.addressFk).toEqual(1); + }); +}); diff --git a/modules/ticket/back/methods/ticket/updateEditableTicket.js b/modules/ticket/back/methods/ticket/updateEditableTicket.js new file mode 100644 index 000000000..7be45a788 --- /dev/null +++ b/modules/ticket/back/methods/ticket/updateEditableTicket.js @@ -0,0 +1,41 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethod('updateEditableTicket', { + description: 'Change data of a ticket', + accessType: 'WRITE', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'Ticket id', + http: {source: 'path'} + }, + { + arg: 'data', + description: 'Model instance data', + type: 'Object', + required: true, + http: {source: 'body'} + } + ], + returns: { + type: 'object', + root: true + }, + http: { + path: '/:id/updateEditableTicket', + verb: 'POST' + } + + }); + Self.updateEditableTicket = async(id, data) => { + let ticketIsEditable = await Self.app.models.Ticket.isEditable(id); + if (!ticketIsEditable) + throw new UserError('This ticket can not be modified'); + + let ticket = await Self.app.models.Ticket.findById(id); + await ticket.updateAttributes(data); + }; +}; diff --git a/modules/ticket/back/models/ticket.js b/modules/ticket/back/models/ticket.js index 093ad283c..a465aa6ea 100644 --- a/modules/ticket/back/models/ticket.js +++ b/modules/ticket/back/models/ticket.js @@ -20,4 +20,5 @@ module.exports = Self => { require('../methods/ticket/getPossibleStowaways')(Self); require('../methods/ticket/canBeInvoiced')(Self); require('../methods/ticket/makeInvoice')(Self); + require('../methods/ticket/updateEditableTicket')(Self); }; diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 307c88833..709b0331e 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -51,8 +51,9 @@ class Controller { changeShipped(response) { if (response === 'ACCEPT') { - let params = {shipped: this.newShipped}; - this.$http.patch(`/ticket/api/Tickets/${this.ticket.id}`, params).then(() => { + let data = {shipped: this.newShipped}; + let query = `/ticket/api/Tickets/${this.ticket.id}/updateEditableTicket`; + this.$http.post(query, data).then(() => { this.vnApp.showSuccess(this.$translate.instant('Shipped hour updated')); this.cardReload(); }); diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index 92939c246..96e87a4ce 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -86,8 +86,8 @@ describe('Ticket Component vnTicketDescriptor', () => { spyOn(controller.$state, 'reload'); spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('POST', `/ticket/api/Tickets/2/makeInvoice`).respond(); - $httpBackend.expect('POST', `/ticket/api/Tickets/2/makeInvoice`).respond(); + $httpBackend.when('POST', '/ticket/api/Tickets/2/makeInvoice').respond(); + $httpBackend.expect('POST', '/ticket/api/Tickets/2/makeInvoice').respond(); controller.makeInvoice('ACCEPT'); $httpBackend.flush(); @@ -100,8 +100,8 @@ describe('Ticket Component vnTicketDescriptor', () => { it('should make a query and show a success snackbar if the response is ACCEPT', () => { spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('POST', `/invoiceOut/api/InvoiceOuts/1/regenerate`).respond(); - $httpBackend.expect('POST', `/invoiceOut/api/InvoiceOuts/1/regenerate`).respond(); + $httpBackend.when('POST', '/invoiceOut/api/InvoiceOuts/1/regenerate').respond(); + $httpBackend.expect('POST', '/invoiceOut/api/InvoiceOuts/1/regenerate').respond(); controller.regenerateInvoice('ACCEPT'); $httpBackend.flush(); @@ -111,10 +111,12 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('changeShipped(response)', () => { it('should make a query and change the shipped hour if the response is ACCEPT', () => { + controller.ticket.id = 12; spyOn(controller.vnApp, 'showSuccess'); spyOn(controller, 'cardReload'); - $httpBackend.when('PATCH', `/ticket/api/Tickets/2`,).respond(); - $httpBackend.expect('PATCH', `/ticket/api/Tickets/2`).respond(); + + $httpBackend.when('POST', '/ticket/api/Tickets/12/updateEditableTicket').respond(); + $httpBackend.expect('POST', '/ticket/api/Tickets/12/updateEditableTicket').respond(); controller.changeShipped('ACCEPT'); $httpBackend.flush(); @@ -123,4 +125,3 @@ describe('Ticket Component vnTicketDescriptor', () => { }); }); }); -