当前位置: 动力学知识库 > 问答 > 编程问答 >

strongloop - Hooks afterUpdate and afterDestroy not called

问题描述:

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?

网友答案:

See an example in my new repo: https://github.com/strongloop/loopback-faq-model-hooks

There is an issue with afterDestroy, the issue is waiting to be resolved

网友答案:

Try to implement your logic with changed and deleted Model's Events

分享给朋友:
您可能感兴趣的文章:
随机阅读: