setDelivered and open delivery notes and tests
This commit is contained in:
parent
fb37e156d4
commit
2abd45f498
|
@ -53,6 +53,6 @@ module.exports = Self => {
|
|||
if (!isAllowed)
|
||||
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
||||
|
||||
return await models.TicketTracking.create(params);
|
||||
return models.TicketTracking.create(params);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('setDelivered', {
|
||||
description: 'Changes the state of the received ticket ids to delivered',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'ticketIds',
|
||||
description: 'the array of ticket ids to set as delivered',
|
||||
type: [],
|
||||
required: true,
|
||||
http: {source: 'body'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'string',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/setDelivered`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.setDelivered = async(ctx, ticketIds) => {
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let models = Self.app.models;
|
||||
|
||||
let state = await models.State.findOne({where: {code: 'delivered'}, fields: ['id']});
|
||||
|
||||
let worker = await models.Worker.findOne({where: {userFk: userId}});
|
||||
|
||||
let promises = [];
|
||||
for (let i = 0; i < ticketIds.length; i++) {
|
||||
let promise = models.TicketTracking.changeState(ctx, {
|
||||
stateFk: state.id,
|
||||
workerFk: worker.id,
|
||||
ticketFk: ticketIds[i]
|
||||
});
|
||||
promises.push(promise);
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket setDelivered()', () => {
|
||||
let ticketOne;
|
||||
let ticketTwo;
|
||||
|
||||
beforeAll(async done => {
|
||||
let originalTicketOne = await app.models.Ticket.findById(8);
|
||||
let originalTicketTwo = await app.models.Ticket.findById(10);
|
||||
|
||||
originalTicketOne.id = null;
|
||||
originalTicketTwo.id = null;
|
||||
ticketOne = await app.models.Ticket.create(originalTicketOne);
|
||||
ticketTwo = await app.models.Ticket.create(originalTicketTwo);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(async done => {
|
||||
await app.models.Ticket.destroyById(ticketOne.id);
|
||||
await app.models.Ticket.destroyById(ticketTwo.id);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return an array of the tickets states changed to delivered', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 49}}};
|
||||
let delivered = await app.models.State.findOne({where: {code: 'delivered'}, fields: ['id']});
|
||||
|
||||
let params = [ticketOne.id, ticketTwo.id];
|
||||
let res = await app.models.TicketTracking.setDelivered(ctx, params);
|
||||
|
||||
expect(res[0].ticketFk).toEqual(ticketOne.id);
|
||||
expect(res[0].stateFk).toEqual(delivered.id);
|
||||
|
||||
expect(res[1].ticketFk).toEqual(ticketTwo.id);
|
||||
expect(res[1].stateFk).toEqual(delivered.id);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
module.exports = function(Self) {
|
||||
require('../methods/ticket-tracking/changeState')(Self);
|
||||
require('../methods/ticket-tracking/setDelivered')(Self);
|
||||
|
||||
Self.validatesPresenceOf('stateFk', {message: 'State cannot be blank'});
|
||||
Self.validatesPresenceOf('workerFk', {message: 'Worker cannot be blank'});
|
||||
|
|
|
@ -123,8 +123,8 @@
|
|||
<vn-button class="round sm vn-mb-sm"
|
||||
icon="print"
|
||||
ng-show="$ctrl.totalChecked > 0"
|
||||
ng-click="$ctrl.openDeliveryNotes()"
|
||||
vn-tooltip="Open delivery note(s)"
|
||||
ng-click="$ctrl.setDelivered()"
|
||||
vn-tooltip="Set as delivered and open delivery note(s)"
|
||||
tooltip-position="left">
|
||||
</vn-button>
|
||||
<vn-button class="round sm vn-mb-sm"
|
||||
|
|
|
@ -4,13 +4,20 @@ import UserError from 'core/lib/user-error';
|
|||
import './style.scss';
|
||||
|
||||
export default class Controller extends Section {
|
||||
openDeliveryNotes() {
|
||||
setDelivered() {
|
||||
const checkedTickets = this.checked;
|
||||
let ids = [];
|
||||
|
||||
for (let ticket of checkedTickets)
|
||||
ids.push(ticket.id);
|
||||
|
||||
this.$http.post('TicketTrackings/setDelivered', ids).then(() => {
|
||||
this.openDeliveryNotes(ids);
|
||||
this.$.model.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
openDeliveryNotes(ids) {
|
||||
for (let id of ids) {
|
||||
const params = {
|
||||
authorization: this.vnToken.token,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import './index.js';
|
||||
describe('Component vnTicketIndex', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $window;
|
||||
let tickets = [{
|
||||
id: 1,
|
||||
|
@ -21,7 +22,8 @@ describe('Component vnTicketIndex', () => {
|
|||
|
||||
beforeEach(ngModule('ticket'));
|
||||
|
||||
beforeEach(inject(($componentController, _$window_) => {
|
||||
beforeEach(inject(($componentController, _$window_, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$window = _$window_;
|
||||
const $element = angular.element('<vn-ticket-index></vn-ticket-index>');
|
||||
controller = $componentController('vnTicketIndex', {$element});
|
||||
|
@ -85,6 +87,21 @@ describe('Component vnTicketIndex', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('setDelivered()/openDeliveryNotes()', () => {
|
||||
it('should perform a post to setDelivered and open tabs with the delivery notes', () => {
|
||||
controller.$.model = {data: tickets, refresh: () => {}};
|
||||
|
||||
$window.open = jest.fn();
|
||||
|
||||
$httpBackend.expect('POST', 'TicketTrackings/setDelivered').respond('ok');
|
||||
controller.setDelivered();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect($window.open).toHaveBeenCalledWith(`api/report/delivery-note?ticketId=${tickets[1].id}`);
|
||||
expect($window.open).toHaveBeenCalledWith(`api/report/delivery-note?ticketId=${tickets[2].id}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('checked()', () => {
|
||||
it('should return an array of checked tickets', () => {
|
||||
controller.$.model = {data: tickets};
|
||||
|
|
|
@ -2,7 +2,7 @@ Weekly tickets: Tickets programados
|
|||
Go to lines: Ir a lineas
|
||||
Not available: No disponible
|
||||
Payment on account...: Pago a cuenta...
|
||||
Open delivery note(s): Abrir albarán/es
|
||||
Set as delivered and open delivery note(s): Marcar como servido/s y abrir albarán/es
|
||||
Closure: Cierre
|
||||
You cannot make a payment on account from multiple clients: No puedes realizar un pago a cuenta de clientes diferentes
|
||||
Filter by selection: Filtro por selección
|
||||
|
|
Loading…
Reference in New Issue