My goal is to send some request after certain model was created, updated or deleted. So I implemented the following:
module.exports = function(TerminalUser) {
var http = require('http');
var tsReloadUser = function(id) {
var options = {
auth: 'user:pwd',
host: 'host.domain.local',
port: 8080,
path: '/CmdUserCacheRefresh?userid=' + id,
method: 'GET'
};
http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
}).end();
}
TerminalUser.afterSave = function(next) {
console.log('afterSave');
tsReloadUser(this.id);
next();
};
TerminalUser.afterUpdate = function(next) {
console.log('afterUpdate');
tsReloadUser(this.id);
next();
}
TerminalUser.afterDestroy = function(next) {
console.log('afterDestroy');
tsReloadUser(this.id);
next();
};
};
The hook afterSave is call when an entity was created and everything runs as expected. But for some strange reason neither afterUpdate/Destroy is called nor a error message is thrown when a user updates or delete an entity instance (the data is successfully stored in the database). Can anyone give me a hint whats going on?