mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
26 lines
567 B
TypeScript
26 lines
567 B
TypeScript
import {
|
|
CanActivate,
|
|
ExecutionContext,
|
|
Inject,
|
|
Injectable,
|
|
Scope,
|
|
} from '@nestjs/common';
|
|
import { Observable } from 'rxjs';
|
|
|
|
@Injectable({ scope: Scope.REQUEST })
|
|
export class Guard implements CanActivate {
|
|
static COUNTER = 0;
|
|
static REQUEST_SCOPED_DATA = [] as number[];
|
|
|
|
constructor(@Inject('REQUEST_ID') private readonly requestId: number) {
|
|
Guard.COUNTER++;
|
|
}
|
|
|
|
canActivate(
|
|
context: ExecutionContext,
|
|
): boolean | Promise<boolean> | Observable<boolean> {
|
|
Guard.REQUEST_SCOPED_DATA.push(this.requestId);
|
|
return true;
|
|
}
|
|
}
|