Considering all the Sequelize information working correctly, I have a model called MyModel and that has its attributes, so far this is correct. However, when I get a data from this model I want to transform the id of my table into a hash to show in the Font, that is, considering the id 4 in the table MyModel in Front it will see something like H7x8Ip, but the afterFind is not changing the value of this id.
module.exports = (sequelize, DataTypes) => {
var MinhaModel = sequelize.define('MinhaModel', {
name: {
allowNull: false,
require: true,
type: DataTypes.STRING
}
},
{
timestamps : true,
underscored : true
});
AccountPlan.hook('afterFind', (data, opt) => {
// chama o modulo do hash
const hash = require('./modules/generaters/hash');
const hashid = await hashids.hash(env).encode(data.id);
// atualiza valor
data.id = hashid;
})
}
The ideal return would be something like:
{
id: H7x8Ip,
name: 'dados_minha_Model'
}
But the return is as if it had brought from the bank, without going through afterFind:
{
id: 1,
name: 'dados_minha_Model'
}
Can anyone explain me better the concept of Sequelize Hooks, how do they work exactly, do I need to go through a Promise or something?