我目前正在使用环回工作预约预约应用,下面是我在common / model目录中的预约.js
module.exports = function(Appointment) {
Appointment.afterCreate = function (next) {
//TODO add appointment details should not be hardcoded get users email here
var emailService = require('../../common/services/email.server.service');
emailService.sendUserEmail('dummy@dummy.com');
next();
};
Appointment.beforeUpdate = function(next) {
var emailService = require('../../common/services/email.server.service');
if(this.appointmentStatus === 'waiting_agent'){
console.log(this.appointmentStatus);
} else if(this.appointmentStatus === 'waiting_user'){
console.log(this.appointmentStatus);
} else {
console.log(this.appointmentStatus);
}
emailService.sendUserEmail('dummy@dummy.com');
next();
};
};
afterCreate函数运行良好并发送电子邮件,但是在AfterUpdate / beforeUpdate不起作用之后,我使用Angular作为前端并使用Angular loopback生成服务,下面是更新函数:
function updateAppointment(listingId,newAppointmentInfo,status){
Appointment.updateAll(
{
where:
{
listingId : listingId
}
},
{
"appointmentDate": newAppointmentInfo.selectedDate,
"appointmentTime" : newAppointmentInfo.selectedTime,
"appointmentStatus" : status
},
function (appointment){
console.log(appointment);
},
function (err){
console.log(err);
}
)
}
是因为我正在调用/约会/更新api而不是更新/约会?
答案 0 :(得分:1)
不赞成使用模型钩子来支持操作和每个方法钩子。见http://docs.strongloop.com/display/LB/Operation+hooks
中的最后一条评论答案 1 :(得分:0)
Loopback在模型挂钩触发方面存在一些问题。 请参阅问题https://github.com/strongloop/loopback-datasource-juggler/issues/202