feat: refs #8387 crudModel #3355
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE `vn`.`tag`
|
||||
ADD COLUMN IF NOT EXISTS `validationRegex` varchar(50) DEFAULT NULL;
|
|
@ -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.findOne({where: {id: 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');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
"mysql": {
|
||||
"columnName": "isQuantitatif"
|
||||
}
|
||||
},
|
||||
"validationRegex": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
|
|
Loading…
Reference in New Issue