Search code examples
javascriptnode.jstypescriptexpressprisma

How to set a column with current time on Prisma?


I'm making a node api using prisma ORM and i'm trying to update a column which i had set with the type DateTime, here is the model, the column is the deleted_at one

model Employee {
 id Int @id @default(autoincrement())
 name String
 created_at DateTime
 deleted_at DateTime
}

how can i change it to the current time in my controller? the controller looks like this

export const DeleteCompany = async (req:IEmployee, res:Response) => {
 const data:ICompany = req
 const deletedCompany = await prisma.employee.update({
     where: {
         id: Number(data.id)
     },
     data: {
        deleted_at: //what should I put here?
     }
 })
 return res.status(200).json(deletedCompany)
}

I've tried using

now()

but it didnt work.


Solution

  • Prisma supports plain javascript dates for setting date fields.

    So new Date() should work fine:

    deleted_at: new Date()