我在执行请求时遇到此错误。(node:3993)[DEP0097] DeprecationWarning:不建议在MakeCallback中使用域属性。改用MakeCallback的async_context变体或AsyncResource类。
即我控制器的代码:AppointmentController队列代码:QueueNodemailer:Mail
async delete(req, res) {
const { appointment_id } = req.params;
if (!appointment_id) {
return res.status(404).json({
error: "It's not possible to cancel an appointment with passing an id",
});
}
const appointment = await Appointment.findByPk(appointment_id, {
include: [
{
model: Restaurant,
as: 'restaurant',
attributes: ['id', 'name', 'provider_id'],
include: [
{
model: Provider,
foreignKey: 'provider_id',
as: 'provider',
},
],
},
{
model: User,
as: 'user',
attributes: ['id', 'name', 'email'],
},
],
});
if (!appointment) {
return res.status(404).json({ error: 'Appointment not found' });
}
if (appointment && appointment.canceled_at !== null) {
return res
.status(420)
.json({ error: 'This appointment was already canceled' });
}
// The user can cancel only his/her appointments - Verifying if the id is different
if (appointment.user_id !== req.userId) {
return res.status(401).json({
error: "You don't have permission to cancel this appointment",
});
}
// It's just allowed to cancel appointments with 1 hour of advance
const dateWithSub = subHours(appointment.date, 1);
if (isBefore(dateWithSub, new Date())) {
return res.status(401).json({
error: 'You can only cancel appointments with 1 hour of advance',
});
}
// Changing the field canceled_at with the current date
appointment.canceled_at = new Date();
await appointment.save();
const formatedDate = format(
appointment.date,
"'Day' dd 'of' MMMM',' H:mm 'Hours'"
);
await Queue.add(CancellationMail.key, { appointment, formatedDate });
return res.json(appointment);
}
}
此外,我正在为电子邮件作业使用队列。问题是,我不知道此错误是与节点有关还是来自我正在使用的服务之一。
如果仍然不能解决问题,那么您需要弄清楚警告的来源,最好的方法是在调试器中逐步检查代码,并在警告出现时查看堆栈跟踪发出。