This commit is contained in:
Felipe Batista
2025-01-27 17:44:27 -03:00
commit 47e7f75720
238 changed files with 36425 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import { ResultModel } from './../domain/models/result.model';
import { Contract } from './../contracts/contract';
import { CallHandler, ExecutionContext, HttpException, HttpStatus, NestInterceptor } from "@nestjs/common";
import { Observable } from "rxjs";
export class ValidadorInterceptor implements NestInterceptor {
constructor(public contract: Contract){}
intercept(context: ExecutionContext, next: CallHandler<any>): Observable<any> {
const body = context.switchToHttp().getRequest().body;
const valid = this.contract.validade(body);
if (!valid) {
throw new HttpException(new ResultModel(false, 'Ops, algo saiu errado!', null, this.contract.errors), HttpStatus.BAD_REQUEST);
}
return next.handle();
}
}