Soft Delete with Nestjs
Hi everyone
How I can implement soft deletes using Prisma and Nestjs?
I found on the docs but is using middlewares, and for what I know, they are deprecated.
Thanks for your time
13 Replies
Anyone can help me please?
Hey @Daniel Sousa @TutoDS 👋
Did you see this extension?
https://github.com/olivierwilkinson/prisma-extension-soft-delete
You can use this extension in your NestJS setup.
GitHub
GitHub - olivierwilkinson/prisma-extension-soft-delete: Prisma exte...
Prisma extension for adding soft delete to Prisma models, even when using nested queries - GitHub - olivierwilkinson/prisma-extension-soft-delete: Prisma extension for adding soft delete to Prisma...
I don’t have the delete field only
deleted_at
and deleted_by
I believe it's not mandatory to use delete field. You can pass your own. In your case it would be
deleted_at
Is psosible to create an extension to fill
created_by
automatically with the logged user?Thanks, but you can get the user from the request.user?
That is an implementation detail. The getCurrentUserId function should return the user id. This may come form your incoming request.
Thanks, I need to see to get the request from Nestjs on Prisma service
Hi @Nurul (Prisma)
Sorry to bother you again
This is my current customers schema, but when I try to create a new one, I need to insert the
updatedBy
, the deletedBy
.
How I can make it optional? Or, what is the best way to handle these cases?In this case you just need to add
?
to the fields like this:
This would make both the fields optional.And how to handle the relation?
@Nurul (Prisma) I try the extends that you suggest me but I got this error
Can you share the entire updated User model and the prisma query with me?