forked from Yara724/api
Validation for prices and objection
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NestInterceptor,
|
||||
} from "@nestjs/common";
|
||||
import { Observable } from "rxjs";
|
||||
import { normalizeUnicodeDigitsDeep } from "src/utils/unicode-digits";
|
||||
|
||||
/**
|
||||
* Normalizes Unicode decimal digits in JSON request bodies to ASCII before
|
||||
* validation and handlers run (Persian/Arabic-Indic → 0-9).
|
||||
*/
|
||||
@Injectable()
|
||||
export class UnicodeDigitsNormalizeInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
||||
const req = context.switchToHttp().getRequest();
|
||||
const contentType = String(req.headers?.["content-type"] ?? "");
|
||||
|
||||
if (
|
||||
req.body &&
|
||||
typeof req.body === "object" &&
|
||||
!Buffer.isBuffer(req.body) &&
|
||||
!contentType.includes("multipart/form-data")
|
||||
) {
|
||||
req.body = normalizeUnicodeDigitsDeep(req.body);
|
||||
}
|
||||
|
||||
return next.handle();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user