Bug #378 Refactorizar marcar como reservado para que no utilice el crud
This commit is contained in:
parent
d36483875b
commit
8a655a7003
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.installCrudModel('crudSale');
|
||||
};
|
|
@ -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});
|
||||
}
|
||||
};
|
||||
};
|
|
@ -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);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
"type": "Number"
|
||||
},
|
||||
"reserved": {
|
||||
"type": "Number"
|
||||
"type": "boolean"
|
||||
},
|
||||
"isPicked": {
|
||||
"type": "Number"
|
||||
|
|
Loading…
Reference in New Issue