feat: refs #8387 crudModel #3355

Merged
robert merged 16 commits from 8387-itemTagCrudModel into dev 2025-01-27 11:38:09 +00:00
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

@ -397,4 +397,4 @@
"Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}",
"Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden.",
"Price cannot be blank": "El precio no puede estar en blanco"
}
}

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) {
robert marked this conversation as resolved
Review

&& de value deberia ir a este nivel no?

&& de value deberia ir a este nivel no?
Review

validTag.validationRegex comprueba si la columna validationRegex de la tabla tag tiene una expresión regular, y en caso de tener, se comprueba si el valor cumple la expresión regular

validTag.validationRegex comprueba si la columna validationRegex de la tabla tag tiene una expresión regular, y en caso de tener, se comprueba si el valor cumple la expresión regular
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": [