I'm using nest js.I have the following scenario where i need to pass customId from controller where i got it using interceptor when i handled the http request. I need to access customId in service without passing it in the props. Is their a way to inject custom variables ?
Asked
Active
Viewed 873 times
2 Answers
0
Adding "customId" is request object req.customId
should work.

Abhishek Singh
- 408
- 1
- 5
-
I already got in my controller but i need to be able to do the following UserController --> UserService --> UserRepository I need to read it from repository without passing it to service than repository – youssef mahdi Jul 06 '22 at 19:17
0
I created an customRepository
@Injectable({scope:Scope.REQUEST})
export class IdService{
id:string='';
public setId(id:string){
this.id=id
}
}
In the controller i inject it and use setId then i read id from userRepository
controller:
this.repo.setId(body.payload.tax)
userReposiotry:
const id= this.repo.id