Merge pull request 'feat: refs #8387 crudModel' (!3355) from 8387-itemTagCrudModel into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #3355
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Robert Ferrús 2025-01-27 11:38:07 +00:00
commit 56982ee1ba
4 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn`.`tag`
ADD COLUMN IF NOT EXISTS `validationRegex` varchar(50) DEFAULT NULL;

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 => {
let tagFk;
let value;
if (ctx.isNewInstance) {
tagFk = ctx.instance.tagFk;
value = ctx.instance.value;
} else {
tagFk = ctx.currentInstance.tagFk;
value = ctx.data.value;
}
const models = Self.app.models;
const validTag = await models.Tag.findById(tagFk);
if (validTag.validationRegex) {
const regexString = validTag.validationRegex.replace(/\\\\/g, '\\');
const validExpresion = new RegExp(regexString);
if (value && !validExpresion.test(value))
throw new UserError('The value must be a number or a range of numbers');
}
});
};

View File

@ -30,6 +30,9 @@
"mysql": {
"columnName": "isQuantitatif"
}
},
"validationRegex": {
"type": "string"
}
},
"acls": [