【发布时间】:2015-02-03 17:09:10
【问题描述】:
我目前正在开发一个使用环回的预约应用程序,下面是我在 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 环回生成服务,下面是更新函数:
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);
}
)
}
是因为我调用的是 /Appointment/update api,而不是 /Appointment 上的 UPDATE 吗?
【问题讨论】:
标签: node.js rest loopbackjs