diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 174a9e093..8d5156842 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -174,5 +174,7 @@ "That item doesn't exists": "Ese artículo no existe", "There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})", "Invalid account": "Cuenta inválida", - "Compensation account is empty": "La cuenta para compensar está vacia" + "Compensation account is empty": "La cuenta para compensar está vacia", + "This genus already exist": "Este genus ya existe", + "This specie already exist": "Esta especie ya existe" } \ No newline at end of file diff --git a/modules/item/back/models/genus.js b/modules/item/back/models/genus.js index 462d5efd4..c105e06b4 100644 --- a/modules/item/back/models/genus.js +++ b/modules/item/back/models/genus.js @@ -1,9 +1,9 @@ -module.exports = Self => { - Self.validatesPresenceOf('name', { - message: 'Name cannot be blank' - }); +let UserError = require('vn-loopback/util/user-error'); - Self.validatesUniquenessOf('id', { - message: 'This name already exist.' +module.exports = Self => { + Self.rewriteDbError(function(err) { + if (err.code === 'ER_DUP_ENTRY') + return new UserError(`This genus already exist`); + return err; }); }; diff --git a/modules/item/back/models/specie.js b/modules/item/back/models/specie.js new file mode 100644 index 000000000..e6a03f851 --- /dev/null +++ b/modules/item/back/models/specie.js @@ -0,0 +1,9 @@ +let UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.rewriteDbError(function(err) { + if (err.code === 'ER_DUP_ENTRY') + return new UserError(`This specie already exist`); + return err; + }); +}; diff --git a/modules/item/back/models/species.js b/modules/item/back/models/species.js deleted file mode 100644 index 462d5efd4..000000000 --- a/modules/item/back/models/species.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = Self => { - Self.validatesPresenceOf('name', { - message: 'Name cannot be blank' - }); - - Self.validatesUniquenessOf('id', { - message: 'This name already exist.' - }); -};