Template
21 lines
479 B
TypeScript
21 lines
479 B
TypeScript
import {
|
|
HttpException,
|
|
HttpStatus,
|
|
Injectable,
|
|
PipeTransform,
|
|
} from '@nestjs/common';
|
|
import { WordService } from '../services/word.service';
|
|
|
|
@Injectable()
|
|
export class WordPipe implements PipeTransform {
|
|
constructor(private readonly wordService: WordService) {}
|
|
|
|
async transform(id: number) {
|
|
const word = await this.wordService.getById(id);
|
|
if (!word) {
|
|
throw new HttpException('Word not found', HttpStatus.NOT_FOUND);
|
|
}
|
|
return word;
|
|
}
|
|
}
|