diff --git a/client/ticket/src/create/index.spec.js b/client/ticket/src/create/index.spec.js new file mode 100644 index 000000000..468e648eb --- /dev/null +++ b/client/ticket/src/create/index.spec.js @@ -0,0 +1,41 @@ +import './index.js'; + +describe('Ticket', () => { + describe('Component vnTicketCreate', () => { + let $componentController; + let $scope; + let controller; + let $state; + + beforeEach(() => { + angular.mock.module('ticket'); + }); + + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => { + $componentController = _$componentController_; + + $scope = $rootScope.$new(); + $scope.card = {createTicket: () => {}}; + $state = _$state_; + $state.go = () => {}; + controller = $componentController('vnTicketCreate', {$scope: $scope, $state: $state}); + })); + + describe('onSubmit()', () => { + it(`should call createTicket()`, () => { + spyOn(controller.$.card, 'createTicket'); + controller.onSubmit(); + + expect(controller.$.card.createTicket).toHaveBeenCalledWith(); + }); + + xit(`should call go()`, () => { + spyOn(controller.$state, 'go'); + controller.onSubmit(); + + expect(controller.$state.go).toHaveBeenCalledWith(); + }); + }); + }); +}); + diff --git a/client/ticket/src/sale/index.html b/client/ticket/src/sale/index.html index b6b0566b7..598e6cb67 100644 --- a/client/ticket/src/sale/index.html +++ b/client/ticket/src/sale/index.html @@ -59,10 +59,11 @@ - + { - line.reserved = reserved; - }); - - this.$http.post(`/ticket/api/Sales/crudSale`, data).then(() => { + this.$http.post(`/ticket/api/Sales/reserve`, params).then(() => { this.$.index.accept(); }); } diff --git a/services/loopback/common/methods/sale/crudSale.js b/services/loopback/common/methods/sale/crudSale.js deleted file mode 100644 index b33d70fc5..000000000 --- a/services/loopback/common/methods/sale/crudSale.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = Self => { - Self.installCrudModel('crudSale'); -}; diff --git a/services/loopback/common/methods/sale/reserve.js b/services/loopback/common/methods/sale/reserve.js new file mode 100644 index 000000000..1370058c4 --- /dev/null +++ b/services/loopback/common/methods/sale/reserve.js @@ -0,0 +1,32 @@ + +module.exports = Self => { + Self.remoteMethod('reserve', { + description: 'Change the state of a ticket', + accessType: '', + accepts: [{ + arg: 'params', + type: 'object', + required: true, + description: '[sales IDs], actualTicketFk, reserved', + http: {source: 'body'} + }], + returns: { + type: 'string', + root: true + }, + http: { + path: `/reserve`, + verb: 'post' + } + }); + + Self.reserve = async params => { + let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk); + if (!thisTicketIsEditable) + throw new Error(`The sales of this ticket can't be modified`); + + for (let i = 0; i < params.sales.length; i++) { + await Self.app.models.Sale.update({id: params.sales[i].id}, {reserved: params.reserved}); + } + }; +}; diff --git a/services/loopback/common/models/sale.js b/services/loopback/common/models/sale.js index 9bd300860..47feb07d8 100644 --- a/services/loopback/common/models/sale.js +++ b/services/loopback/common/models/sale.js @@ -2,8 +2,8 @@ module.exports = Self => { require('../methods/sale/filter')(Self); require('../methods/sale/saleComponentFilter')(Self); require('../methods/sale/priceDifference')(Self); - require('../methods/sale/crudSale')(Self); require('../methods/sale/moveToTicket')(Self); + require('../methods/sale/reserve')(Self); require('../methods/sale/moveToNewTicket')(Self); require('../methods/sale/removes')(Self); require('../methods/sale/updateDiscount')(Self); diff --git a/services/loopback/common/models/sale.json b/services/loopback/common/models/sale.json index 562eecfc7..7dc61cc09 100644 --- a/services/loopback/common/models/sale.json +++ b/services/loopback/common/models/sale.json @@ -25,7 +25,7 @@ "type": "Number" }, "reserved": { - "type": "Number" + "type": "boolean" }, "isPicked": { "type": "Number"