when i receive the req.query and I pass it to in my insomnia a date value and a make a request all is going fine but when I receive the date it says that is invalid like you see in the screen from my logs I try to see value with console.log, and always when I received it from req.query, even when I use parsedISO, and I dont know why, can someone helps me?
I use isValid to verify my date and it returns false
Here me code and some screens:
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);
}
the error returned is:
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.