diff --git a/modules/ticket/back/methods/sale/priceDifference.js b/modules/ticket/back/methods/sale/priceDifference.js index c744a8321..65c3dd80f 100644 --- a/modules/ticket/back/methods/sale/priceDifference.js +++ b/modules/ticket/back/methods/sale/priceDifference.js @@ -1,6 +1,8 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { Self.remoteMethod('priceDifference', { - description: 'Returns sales with price difference', + description: 'Returns sales with price difference if the ticket is editable', accessType: 'READ', accepts: [{ arg: 'ticketFk', @@ -26,6 +28,10 @@ module.exports = Self => { }); Self.priceDifference = async(ticketFk, data) => { + let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(ticketFk); + if (!thisTicketIsEditable) + throw new UserError(`The sales of this ticket can't be modified`); + let filter = { where: { ticketFk: ticketFk diff --git a/modules/ticket/front/data/step-one/index.js b/modules/ticket/front/data/step-one/index.js index 54aac4c2f..125c10a75 100644 --- a/modules/ticket/front/data/step-one/index.js +++ b/modules/ticket/front/data/step-one/index.js @@ -118,7 +118,7 @@ class Controller { }); } - async onStepChange(state) { + async onStepChange() { if (this.isFormInvalid()) { return this.vnApp.showError( this.$translate.instant('Some fields are invalid') @@ -138,11 +138,15 @@ class Controller { this.ticket.sale = res.data; return true; - }, res => { - if (res.data.error.message === 'NO_AGENCY_AVAILABLE') { + }, err => { + if (err.data.error.message === 'NO_AGENCY_AVAILABLE') { this.vnApp.showMessage( this.$translate.instant(`There's no available agency for this landing date`) ); + } else { + this.vnApp.showMessage( + this.$translate.instant(err.data.error.message) + ); } }); }