Files
webapp-back/src/word/pipe/word.pipe.ts
T
2024-12-29 12:04:19 +01:00

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;
}
}