I am using prisma schema with mongodb and what I am doing is having a date be generated like so:
model Book {
id String @id @default(dbgenerated()) @map("_id") @db.ObjectId
title String
author Author @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId
createdAt DateTime @default(now())
}
node.createdAt is showing: 2021-11-29T12:38:22.248Z
So the tricky thing is a have two functions, one takes in a node from a list of edges and gets the createdAt property on the node the other converts the cursor back.
To convert the createdAt property I did this:
Buffer.from((node.createdAt).getTime().toString()).toString('base64')
which gives me:
MTYzODE4OTUwMjI0OA==
Now to convert it back I have a function that takes in a cursor which I handled like this:
return new Date(parseInt(Buffer.from(cursor, 'base64').toString()))
this returns the same thing back: 2021-11-29T12:38:22.248Z
This is not working however and I think it's because the new Date returns a new instance. I'm having some real trouble getting this one to work