微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。