Nestjs Prisma extension
Hi everyone
I'm trying to fill the
code
field with a custom nanoid()
with only uppercase letters and numbers, but when I do the $extends
with my logic, I have two problems:
- I think my custom nanoid()
isn't working
- Typescript is complaining because I didn't fill the code on the .create
This is my prisma service:
8 Replies
I changed my
$extends
to this:
But not working...Hi @Daniel Sousa @TutoDS
Can you modify your code to look like
Is throwing this
console.log(args)
returning undefined
Can you modify your extension to use $allOperations instead of targeting a specific model operation:
Didn't work...
Is generating a random nanoid without following the alphabet and the length
but this way I think it's working
@RaphaelEtim By the way, I have the
createdBy
, updatedBy
and deleteBy
fields. Is possible to create an $extends
to fill this with the current logged user?
I already try to do it, but inside the onModuleInit
because I need to inject the requestit is possible to use Prisma Client Extensions to automatically fill the createdBy, updatedBy, and deletedBy fields with the current logged-in user.
You will need an extension function that takes the user information as an argument. This way, you can create a new extended Prisma client instance for each request, with the current user's information.
can you share an example please?