Bug #378 Refactorizar marcar como reservado para que no utilice el crud

This commit is contained in:
gerard 2018-07-03 15:00:16 +02:00
parent d36483875b
commit 8a655a7003
7 changed files with 87 additions and 27 deletions

View File

@ -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();
});
});
});
});

View File

@ -59,10 +59,11 @@
</thead>
<tbody>
<tr ng-repeat="sale in index.model.instances track by sale.id">
<td ng-show="sale.disponible" ><vn-icon icon="icon-reserved"></vn-icon></td>
<td><vn-icon ng-show="sale.reserved" icon="icon-reserved"></vn-icon></td>
<!-- <td>
<vn-icon icon="warning"></vn-icon>
<vn-icon icon="icon-reserved"></vn-icon>
<vn-icon ng-show="sale.disponible" icon="warning"></vn-icon>
<vn-icon ng-show="sale.disponible" icon="warning"></vn-icon>
<vn-icon ng-show="sale.disponible" icon="icon-reserved"></vn-icon>
</td> -->
<td number>
<vn-check

View File

@ -302,13 +302,6 @@ class Controller extends FilterTicketList {
}
}
/**
* Mark sale as reserved
*/
markAsReserved() {
this.setReserved(true);
}
/**
* Unmark sale as reserved
*/
@ -317,21 +310,17 @@ class Controller extends FilterTicketList {
}
/**
* Mark/Unmark sale as reserved from selected lines
* @param {Boolean} reserved reserved
* Mark sale as reserved
*/
markAsReserved() {
this.setReserved(true);
}
setReserved(reserved) {
let data = {
delete: [],
create: [],
update: this.getCheckedLines()
};
let sales = this.getCheckedLines();
let params = {sales: sales, ticketFk: this.ticket.id, reserved: reserved};
data.update.forEach(line => {
line.reserved = reserved;
});
this.$http.post(`/ticket/api/Sales/crudSale`, data).then(() => {
this.$http.post(`/ticket/api/Sales/reserve`, params).then(() => {
this.$.index.accept();
});
}

View File

@ -1,3 +0,0 @@
module.exports = Self => {
Self.installCrudModel('crudSale');
};

View File

@ -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});
}
};
};

View File

@ -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);

View File

@ -25,7 +25,7 @@
"type": "Number"
},
"reserved": {
"type": "Number"
"type": "boolean"
},
"isPicked": {
"type": "Number"