Error due to Date when I try to update a DB record

Hello everybody! I have a really weird issue and I don't understand: I have created a Postgres DB record with this code:
...code before...
await.db
.insert(MyTable)
.values({
...data,
createdAt: new Date(),
updatedAt: new Date(),
})
...code after...
...code before...
await.db
.insert(MyTable)
.values({
...data,
createdAt: new Date(),
updatedAt: new Date(),
})
...code after...
And since here everything is fine. When I am going to update my record, I would like to do something like:
...code before...
await db
.update(MyTable)
.set({
...data,
updatedAt: new Date(),
})
...code after...
...code before...
await db
.update(MyTable)
.set({
...data,
updatedAt: new Date(),
})
...code after...
But I am receiving this error TypeError: value.toISOString is not a function. I think I know what is the problem cause I have encountered it before, when I tried to save the createdAt an updatedAt from the request body from the front end, passing them new Date() as values. I think that now, when I am spreading my ...data I have a createdAt field inside of it that causes me that error, but it has no sense! My DB schema for those two Dates is:
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().notNull(),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().notNull(),
Why I am receiving that error? It seems like something broken is happening behind the scenes. Thanks for the help!
1 Reply
Isitfato
Isitfato5mo ago
I think I am having the same issue -- Weirdly it's only happening in prod and not locally
Want results from more Discord servers?
Add your server