import { Injectable, PipeTransform } from '@nestjs/common'; import { isMongoId } from 'class-validator'; import { RESTError } from '../models/wrappers/rest-wrapper.class'; @Injectable() export class ValidateMongoIdPipe implements PipeTransform { transform(value: string): string { const check = isMongoId(value); if (check) { return value; } else { throw new RESTError('INVALID_MONGO_ID', value); } } }