src/session/session.pipe.ts
Methods |
constructor(sessionService: SessionService)
|
||||||
Defined in src/session/session.pipe.ts:6
|
||||||
Parameters :
|
transform | ||||||
transform(sessionId: string)
|
||||||
Defined in src/session/session.pipe.ts:9
|
||||||
Parameters :
Returns :
Promise<Session>
|
import { Injectable, NotFoundException, PipeTransform } from "@nestjs/common";
import { Session } from "./entities/session.entity";
import { SessionService } from "./session.service";
@Injectable()
export class SessionPipe implements PipeTransform<string, Promise<Session>> {
constructor(private readonly sessionService: SessionService) {}
transform(sessionId: string): Promise<Session> {
if (!sessionId) {
throw new NotFoundException(
"Session ID not found in request parameters",
);
}
return this.sessionService.get(sessionId).catch(() => {
throw new NotFoundException(
`Session with ID ${sessionId} not found`,
);
});
}
}