diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 80da13ae5..e6b7b98c1 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -250,5 +250,6 @@ "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fcee0e111..93ba0d59a 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -398,5 +398,6 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", "Price cannot be blank": "Price cannot be blank", - "There are tickets to be invoiced": "La zona tiene tickets por facturar" -} + "There are tickets to be invoiced": "La zona tiene tickets por facturar", + "The value must be a number or a range of numbers": "The value must be a number or a range of numbers" +} \ No newline at end of file diff --git a/modules/item/back/models/item-tag.js b/modules/item/back/models/item-tag.js index 5b7163913..338ef64cf 100644 --- a/modules/item/back/models/item-tag.js +++ b/modules/item/back/models/item-tag.js @@ -10,4 +10,27 @@ module.exports = Self => { return new UserError(`Tag value cannot be blank`); return err; }); + + Self.observe('before save', async ctx => { + const validValue = new RegExp('^\\d{1,3}(-\\d{1,3})?$'); + let tagFk; + let value; + + if (ctx.isNewInstance) { + tagFk = ctx.instance.tagFk; + value = ctx.instance.value; + } + const newData = ctx.data.value || null; + const currentData = ctx.currentInstance.value || null; + const models = Self.app.models; + const validTag = await models.Tag.findOne({where: {name: 'Longitud(cm)'}}); + + if (tagFk === validTag.id || (currentData && currentData === validTag.id)) { + if ( + (value && !validValue.test(value)) || + (newData && !validValue.test(newData)) + ) + throw new UserError('The value must be a number or a range of numbers'); + } + }); };