loopbackjs - Modifying ctx.result does not change POST response -
i'm modifying ctx.result
on model's after save
operation hook simplify response of post method. response should contain generated id
, response property not part of model:
mymodel.observe('after save', function(ctx, next) { if (ctx.instance && ctx.isnewinstance) { ctx.result = { id : ctx.instance.id, responseonlyproperty: mymodel.getresponseonlypropertyvalue() }; console.log('result:', ctx.result); } next(); });
as expected ctx.result
written console new values set, response body sent client still contains model properties, , not contain newly added responseonlyproperty
.
what proper way modify response body?
they suggest use afterremote hooks adjust response: how modify responses loopback sends. so, move logic implemented method. likely, ctx.result populated on later stage , that's why whatever put ctx.result in model hook, overridden later.
Comments
Post a Comment