diff --git a/back/models/bank-entity.js b/back/models/bank-entity.js index c89e0b364..ac352f93c 100644 --- a/back/models/bank-entity.js +++ b/back/models/bank-entity.js @@ -8,6 +8,26 @@ module.exports = Self => { }); Self.validatesUniquenessOf('bic', { - message: 'This BIC already exist.' + message: 'This BIC already exist' }); + + Self.validatesPresenceOf('countryFk', { + message: 'CountryFK cannot be empty' + }); + + Self.validateAsync('bic', checkBic, { + message: 'Bank entity id must be specified' + }); + async function checkBic(err, done) { + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code.toLowerCase() : null; + + if (code == 'es' && !this.id) + err(); + done(); + } }; diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 10ab08d57..7e010e1b5 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -198,6 +198,7 @@ "Booking completed": "Booking complete", "The ticket is in preparation": "The ticket [{{ticketId}}]({{{ticketUrl}}}) of the sales person {{salesPersonId}} is in preparation", "You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets", + "Bank entity must be specified": "Bank entity must be specified", "Try again": "Try again", "keepPrice": "keepPrice", "Cannot past travels with entries": "Cannot past travels with entries", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5c7dc41b6..1dd70b633 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -338,5 +338,6 @@ "The alias cant be modified": "Este alias de correo no puede ser modificado", "No tickets to invoice": "No hay tickets para facturar", "Name should be uppercase": "El nombre debe ir en mayúscula", + "Bank entity must be specified": "La entidad bancaria es obligatoria", "An email is necessary": "Es necesario un email" }