SequelizeDatabaseError:带时区的时间戳类型的无效输入语法:“无效日期”,来自 date-fns 的 ParseISO 返回无效日期

问题描述

当我收到 req.query 并将其传递给失眠时,日期值和发出请求一切正常,但是当我收到日期时,它说无效,就像您在屏幕中看到的那样我的日志我尝试使用 console.log 查看价值,并且总是在我从 req.query 收到它时,即使我使用 parsedisO,但我不知道为什么,有人可以帮助我吗? 我使用 isValid 来验证我的日期,它返回 false

这是我的代码和一些屏幕:

const date = req.query;
console.log(date);
const parsedDate = parseISO(date);
const startDay = startOfDay(parsedDate);

const endDay = endOfDay(parsedDate);

const appointments = await Appointment.findAll({
  where: [
    {
      provider_id: req.userId,canceled_at: null,date: {
        [Op.between]: [startDay,endDay],},],order: ['date'],});

return res.json(appointments);

}

返回的错误是:

Executing (default): SELECT "id","date","canceled_at","created_at" AS "createdAt","updated_at" AS "updatedAt","user_id","provider_id" FROM "appointments" AS "Appointments" WHERE (("Appointments"."provider_id" = 2 AND "Appointments"."canceled_at" IS NULL AND "Appointments"."date" BETWEEN 'Invalid date' AND 'Invalid date')) ORDER BY "Appointments"."date";
(node:37307) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: invalid input Syntax for type timestamp with time zone: "Invalid date"
    at Query.formatError (/Users/dariocoronel/Desktop/practices/Gostack/javascript/repo/backend/api/node_modules/sequelize/lib/dialects/postgres/query.js:386:16)
    at Query.run (/Users/dariocoronel/Desktop/practices/Gostack/javascript/repo/backend/api/node_modules/sequelize/lib/dialects/postgres/query.js:87:18)
    at processticksAndRejections (internal/process/task_queues.js:97:5)
(node:37307) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:37307) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Screen from my logs in my code

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)