javascript - 节点错误 - 在 MakeCallback 中使用域属性已被弃用
问题描述
我在执行请求时收到此错误。
(节点:3993)[DEP0097] DeprecationWarning:不推荐在 MakeCallback 中使用域属性。请改用 MakeCallback 的 async_context 变体或 AsyncResource 类。
那是我的控制器的代码:AppointmentController 队列的代码:Queue Nodemailer: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);
}
}
另外,我正在为电子邮件作业使用队列。问题是,我不知道这个错误是与节点有关还是来自我正在使用的服务之一。
解决方案
由于使用了已弃用的域模块,因此正在发生弃用警告。
我没有看到您的代码直接使用它,因此,我很确定您需要的软件包之一正在使用它。首先,我会检查您自己的代码以确保您没有使用它,如果没有,请确保您的所有依赖项都是最新的。
如果仍然无法解决,那么您需要找出警告的来源,最好的方法是在调试器中单步执行您的代码,并查看发出此警告时的堆栈跟踪是什么。
推荐阅读
- java - 当前平台不支持 ICON_IMAGE 功能
- c# - c# Json.net 不可变类
- java - 如何使用 cucumber 和 selenium 在一个 java 类中定义所有步骤定义?
- python-3.x - 使用 pygame 在 Python 中编程
- java - 使用 IOException 编写类后无法创建 JAXBContext
- php - 如何在codeigniter中选择最大数据
- vba - 从多个工作簿复制具有不同列和工作表名称的数据 - VBA
- html - 使用 ASP.NET MVC Helpers 自定义样式的单选按钮
- pyspark - Pyspark:添加新列的行值总和超过 255 列
- arrays - 尝试看看是否有更好的方法来重建对象