26 lines
633 B
JavaScript
26 lines
633 B
JavaScript
const validator = require('validator');
|
|
const Sequelize = require('./models').Sequelize;
|
|
|
|
module.exports = class Utils {
|
|
/**
|
|
* Validates a UUID string.
|
|
* @param {*} value - The value to validate as UUID
|
|
* @returns {string|null} - The valid UUID string, or null if invalid
|
|
*/
|
|
static uuid(value) {
|
|
if (value && validator.isUUID(String(value))) {
|
|
return value;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static ilike(model, column, value) {
|
|
return Sequelize.where(
|
|
Sequelize.fn('lower', Sequelize.col(`${model}.${column}`)),
|
|
{
|
|
[Sequelize.Op.like]: `%${value}%`.toLowerCase(),
|
|
},
|
|
);
|
|
}
|
|
};
|