This commit is contained in:
parent
92eef27f37
commit
73eca9905e
|
@ -55,5 +55,6 @@
|
|||
"This ticket can not be modified": "This ticket can not be modified",
|
||||
"You can't delete a confirmed order": "You can't delete a confirmed order",
|
||||
"Value has an invalid format": "Value has an invalid format",
|
||||
"The postcode doesn't exists. Ensure you put the correct format": "The postcode doesn't exists. Ensure you put the correct format"
|
||||
"The postcode doesn't exists. Ensure you put the correct format": "The postcode doesn't exists. Ensure you put the correct format",
|
||||
"Can't create stowaway for this ticket": "Can't create stowaway for this ticket"
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('canBeStowawayed', {
|
||||
description: 'Returns if a ticket can be stowawayed',
|
||||
Self.remoteMethod('canHaveStowaway', {
|
||||
description: 'Returns if a ticket can have stowaway',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
|
@ -14,14 +14,15 @@ module.exports = Self => {
|
|||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/canBeStowawayed`,
|
||||
path: `/:id/canHaveStowaway`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.canBeStowawayed = async id => {
|
||||
const ticket = await Self.app.models.Ticket.findById(id);
|
||||
const warehouse = await Self.app.models.Warehouse.findById(ticket.warehouseFk);
|
||||
Self.canHaveStowaway = async id => {
|
||||
const models = Self.app.models;
|
||||
const ticket = await models.Ticket.findById(id);
|
||||
const warehouse = await models.Warehouse.findById(ticket.warehouseFk);
|
||||
|
||||
if (warehouse && warehouse.hasStowaway)
|
||||
return true;
|
|
@ -21,12 +21,13 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.getPossibleStowaways = async ticketFk => {
|
||||
let canStowaway = await Self.app.models.Ticket.canBeStowawayed(ticketFk);
|
||||
const models = Self.app.models;
|
||||
const canHaveStowaway = await models.Ticket.canHaveStowaway(ticketFk);
|
||||
|
||||
if (!canStowaway)
|
||||
if (!canHaveStowaway)
|
||||
throw new UserError(`Can't create stowaway for this ticket`);
|
||||
|
||||
let ship = await Self.app.models.Ticket.findById(ticketFk);
|
||||
let ship = await models.Ticket.findById(ticketFk);
|
||||
|
||||
if (!ship || !ship.shipped)
|
||||
return [];
|
||||
|
@ -38,7 +39,7 @@ module.exports = Self => {
|
|||
highestDate.setHours(23, 59, 59);
|
||||
|
||||
|
||||
let possibleStowaways = await Self.app.models.Ticket.find({
|
||||
let possibleStowaways = await models.Ticket.find({
|
||||
where: {
|
||||
id: {neq: ticketFk},
|
||||
clientFk: ship.clientFk,
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('ticket canBeStowawayed()', () => {
|
||||
describe('ticket canHaveStowaway()', () => {
|
||||
it('should return true if the ticket warehouse have hasStowaway equal 1', async() => {
|
||||
const ticketId = 16;
|
||||
let canStowaway = await app.models.Ticket.canBeStowawayed(ticketId);
|
||||
let canStowaway = await app.models.Ticket.canHaveStowaway(ticketId);
|
||||
|
||||
expect(canStowaway).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return false if the ticket warehouse dont have hasStowaway equal 0', async() => {
|
||||
const ticketId = 10;
|
||||
let canStowaway = await app.models.Ticket.canBeStowawayed(ticketId);
|
||||
let canStowaway = await app.models.Ticket.canHaveStowaway(ticketId);
|
||||
|
||||
expect(canStowaway).toBeFalsy();
|
||||
});
|
|
@ -3,21 +3,22 @@ const UserError = require('vn-loopback/util/user-error');
|
|||
|
||||
module.exports = function(Self) {
|
||||
Self.observe('before save', async function(ctx) {
|
||||
let isStowaway = await Self.app.models.Ticket.canBeStowawayed(ctx.instance.id);
|
||||
const models = Self.app.models;
|
||||
const canHaveStowaway = await models.Ticket.canHaveStowaway(ctx.instance.shipFk);
|
||||
|
||||
if (!isStowaway)
|
||||
if (!canHaveStowaway)
|
||||
throw new UserError(`Can't create stowaway for this ticket`);
|
||||
|
||||
if (ctx.isNewInstance) {
|
||||
let where = {
|
||||
code: 'BOARDING'
|
||||
};
|
||||
let state = await Self.app.models.State.findOne({where});
|
||||
let state = await models.State.findOne({where});
|
||||
let params = {ticketFk: ctx.instance.id, stateFk: state.id};
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
|
||||
let httpCtx = {req: loopBackContext.active};
|
||||
await Self.app.models.TicketTracking.changeState(httpCtx, params);
|
||||
await models.TicketTracking.changeState(httpCtx, params);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ module.exports = Self => {
|
|||
require('../methods/ticket/uploadFile')(Self);
|
||||
require('../methods/ticket/addSale')(Self);
|
||||
require('../methods/ticket/transferSales')(Self);
|
||||
require('../methods/ticket/canBeStowawayed')(Self);
|
||||
require('../methods/ticket/canHaveStowaway')(Self);
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
if (ctx.isNewInstance) return;
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
<vn-crud-model
|
||||
url="/api/Tickets/{{$ctrl.$stateParams.id}}/getPossibleStowaways"
|
||||
vn-id="model"
|
||||
data="possibleStowaways">
|
||||
</vn-crud-model>
|
||||
<vn-dialog
|
||||
vn-id="dialog"
|
||||
class="modal-form"
|
||||
on-open="$ctrl.getPossibleStowaways()">
|
||||
on-open="model.reload()">
|
||||
<tpl-body>
|
||||
<vn-horizontal pad-medium class="header">
|
||||
<h5><span translate>Stowaways to add</span></h5>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal pad-medium>
|
||||
<vn-table>
|
||||
<vn-table model="model">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th number>Ticket id</vn-th>
|
||||
|
@ -18,7 +23,7 @@
|
|||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="ticket in $ctrl.possibleStowaways" class="clickable" ng-click="$ctrl.addStowaway($index)">
|
||||
<vn-tr ng-repeat="ticket in possibleStowaways" class="clickable" ng-click="$ctrl.addStowaway(ticket)">
|
||||
<vn-td number>{{ticket.id}}</vn-td>
|
||||
<vn-td number>{{ticket.landed | dateTime: 'dd/MM/yyyy'}}</vn-td>
|
||||
<vn-td number>{{ticket.agencyMode.name}}</vn-td>
|
||||
|
|
|
@ -1,23 +1,16 @@
|
|||
import ngModule from '../module';
|
||||
|
||||
class Controller {
|
||||
constructor($state, $, $http, vnApp, $translate) {
|
||||
constructor($stateParams, $, $http, vnApp, $translate) {
|
||||
this.vnApp = vnApp;
|
||||
this.$translate = $translate;
|
||||
this.$ = $;
|
||||
this.$state = $state;
|
||||
this.$stateParams = $stateParams;
|
||||
this.$http = $http;
|
||||
}
|
||||
|
||||
getPossibleStowaways() {
|
||||
this.$http.get(`/api/Tickets/${this.ticket.id}/getPossibleStowaways`)
|
||||
.then(res => {
|
||||
this.possibleStowaways = res.data;
|
||||
});
|
||||
}
|
||||
|
||||
addStowaway(index) {
|
||||
let params = {id: this.possibleStowaways[index].id, shipFk: this.ticket.id};
|
||||
addStowaway(stowaway) {
|
||||
let params = {id: stowaway.id, shipFk: this.ticket.id};
|
||||
this.$http.post(`/api/Stowaways/`, params)
|
||||
.then(() => {
|
||||
this.cardReload();
|
||||
|
@ -35,7 +28,7 @@ class Controller {
|
|||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate'];
|
||||
Controller.$inject = ['$stateParams', '$scope', '$http', 'vnApp', '$translate'];
|
||||
|
||||
ngModule.component('vnAddStowaway', {
|
||||
template: require('./addStowaway.html'),
|
||||
|
|
|
@ -158,7 +158,10 @@
|
|||
question="You are going to delete this ticket"
|
||||
message="This ticket will be removed from current route! Continue anyway?">
|
||||
</vn-confirm>
|
||||
<vn-add-stowaway vn-id="addStowaway" card-reload="$ctrl.cardReload()" ticket="$ctrl.ticket"></vn-add-stowaway>
|
||||
<vn-add-stowaway vn-id="addStowaway"
|
||||
card-reload="$ctrl.cardReload()"
|
||||
ticket="$ctrl.ticket">
|
||||
</vn-add-stowaway>
|
||||
<vn-remove-stowaway vn-id="removeStowaway" card-reload="$ctrl.cardReload()" ticket="$ctrl.ticket"></vn-remove-stowaway>
|
||||
<vn-confirm
|
||||
vn-id="confirm-dialog"
|
||||
|
|
|
@ -41,14 +41,6 @@ class Controller {
|
|||
];
|
||||
}
|
||||
|
||||
set canShowStowaway(value) {
|
||||
this._canShowStowaway = value;
|
||||
}
|
||||
|
||||
get canShowStowaway() {
|
||||
return this._canShowStowaway;
|
||||
}
|
||||
|
||||
showChangeShipped() {
|
||||
if (!this.isEditable) {
|
||||
this.vnApp.showError(this.$translate.instant('This ticket can\'t be modified'));
|
||||
|
@ -81,7 +73,7 @@ class Controller {
|
|||
canStowaway() {
|
||||
if (!this.isTicketModule()) return;
|
||||
|
||||
this.$http.get(`/api/Tickets/${this.ticket.id}/canBeStowawayed`).then(response => {
|
||||
this.$http.get(`/api/Tickets/${this.ticket.id}/canHaveStowaway`).then(response => {
|
||||
if (response.data === true)
|
||||
return this.canShowStowaway = true;
|
||||
|
||||
|
|
|
@ -135,12 +135,33 @@ describe('Ticket Component vnTicketDescriptor', () => {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
describe('showAddStowaway()', () => {
|
||||
it('should show a dialog with a list of tickets available for an stowaway', () => {
|
||||
controller.$scope.addStowaway = {};
|
||||
controller.$scope.addStowaway.show = jasmine.createSpy('show');
|
||||
controller.showAddStowaway();
|
||||
|
||||
expect(controller.$scope.addStowaway.show).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('showRemoveStowaway()', () => {
|
||||
it('should show a dialog for an stowaway removal', () => {
|
||||
controller.$scope.removeStowaway = {};
|
||||
controller.$scope.removeStowaway.show = jasmine.createSpy('show');
|
||||
controller.showRemoveStowaway();
|
||||
|
||||
expect(controller.$scope.removeStowaway.show).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('canStowaway()', () => {
|
||||
it('should make a query and return if the ticket can be stowawayed', () => {
|
||||
controller.ticket.id = 16;
|
||||
spyOn(controller, 'isTicketModule').and.callThrough();
|
||||
$httpBackend.when('GET', '/api/Tickets/16/canBeStowawayed').respond(true);
|
||||
$httpBackend.expect('GET', '/api/Tickets/16/canBeStowawayed').respond(true);
|
||||
$httpBackend.when('GET', '/api/Tickets/16/canHaveStowaway').respond(true);
|
||||
$httpBackend.expect('GET', '/api/Tickets/16/canHaveStowaway').respond(true);
|
||||
controller.canStowaway();
|
||||
$httpBackend.flush();
|
||||
|
||||
|
|
Loading…
Reference in New Issue