feat: refs #8387 crudModel
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Robert Ferrús 2025-01-13 14:29:13 +01:00
parent 98b68a2c74
commit 050c338ffb
3 changed files with 28 additions and 3 deletions

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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');
}
});
};