You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Hello, I'm discovering Nestjs and got a question about interceptors: is it possible to implement an interceptor on something that is not a controller ? I want to implement a custom cache using a decorator. I have a FooController that calls a FooService that calls a FooRepository. FooRepository calls a REST endpoint that give me limited rate and latency so I want to be able to cache that result. I can't do the caching a FooController level because FooService is creating a JWT token.
@Controller('foo')
export class FooController {
constructor(private readonly fooService: FooService) {}
@Get(':whatever')
public async getFoo(@Param('whatever') whatever: string) {
return this.fooService.getFoo(whatever);
}
}
@Injectable()
export class FooService {
constructor(private readonly fooRepository: FooRepository) {}
public async getFoo(whatever: string) {
const res = this.fooRepository.getFoo(whatever);
// do some other things
return res;
}
}
@Injectable()
export class FooRepository {
@Cached()
public async getFoo(whatever: string) {
return http.get(...)
}
}
I currently use my own @cached typescript decorator.
But what if I want to use nestjs resources there? (for instance an injectable redis client). I'm looking for something similar to the NestInterceptor implementation (https://docs.nestjs.com/interceptors).
The text was updated successfully, but these errors were encountered:
Is it possible to implement an interceptor on something that is not a controller
I believe that it was discussed a couple of times already. I'd suggest looking through existing, closed issues, you will surely find a more detailed answer.
I'm submitting a...
Current behavior
Hello, I'm discovering Nestjs and got a question about interceptors: is it possible to implement an interceptor on something that is not a controller ? I want to implement a custom cache using a decorator. I have a FooController that calls a FooService that calls a FooRepository. FooRepository calls a REST endpoint that give me limited rate and latency so I want to be able to cache that result. I can't do the caching a FooController level because FooService is creating a JWT token.
I currently use my own @cached typescript decorator.
But what if I want to use nestjs resources there? (for instance an injectable redis client). I'm looking for something similar to the NestInterceptor implementation (https://docs.nestjs.com/interceptors).
The text was updated successfully, but these errors were encountered: