Hi everyone.
Let me customize this.
Now you can notice because this is the class okay.
This interceptor is a class.
So we have a constructor.
How we use that, private readonly I will call here will be "dtoClass"
Okay.
That's what we want
And here I will replace this.dtoClass
And if you hover it will be the any.
Right.
And here we also any, actually we don't need to fix that.
Because we want to reuse.
And if I remove now inside the post controller, post controller right here.
I will use the new
Right on the new
And the new, it take one argument will be the dtoClass, right?
For that reason I will pass the ResponseDTO right here
Okay.
And that's all.
If I send okay, it also work.
Right?
And later if we have a userDTO, we can easily change it inside the user DTO right here.
Okay.
And let me show you one more way how to increase the code a little bit because it's very hard to remember.
Right.
So for that reason we will use the concept called Custom decorator.
Let me go to the topic right here and I will copy everything.
Okay.
And inside the src, I will create decorators and I will give it a transform
transform-dto.decorator.ts
And then let me paste everything right here.
Oh actually I think I don't need to use
Sorry, I don't need that.
My bad, my bad.
I don't need the here
I only need, convert it inside a function, and it will be enough.
Right.
Let me see.
I will go to the transform DTO interceptor
Okay.
The code right here is a little bit.
Long, right.
So I will show you how we can customize one more step.
Okay.
So here I think I will create.
The function will be.
use
I will cut this line here and UseTransform or TransformDTO, okay. paste it
I will return the code right here.
And in here I will pass the DTO.
pass dto
Directly right here, and I will export the function.
And right now I can use the @TransformDTO and pass
The.
DTO
ResponsePostDTO
....
Okay.
So.
That's it, that for the class right here.
And if I get all of that, now you can see it already worked, right?
Very cool.
But if you want
Mark is not "any" inside here.
If you want to add a little bit of TypeScript checking, we can use the class.
The class constructor from class transformer.
Okay.
With class constructor, we can pass the decorator concept.
And in here I will pass the decorator.
And in here.
also
Using the T
right here
Okay.
This is just the generic concept.
Okay.
But actually we don't need to care about that.
Just make sure this is the class.
Because for example, if I want something like this.
Right.
It will not work if you use any.
This is work, right?
I want to ask a little bit of checking.
For that reason, I used the some thing called class constructor from class transformer.
So that's for the video.
And I will see you in the next one.