hotbug(server): interceptors order

This commit is contained in:
Ahmed Bouhuolia
2026-01-21 13:07:03 +02:00
parent 78b1e9136a
commit d7331554ad
2 changed files with 8 additions and 5 deletions

View File

@@ -5,15 +5,18 @@ import {
NestInterceptor,
} from '@nestjs/common';
import { Observable, map } from 'rxjs';
import { mapValues, mapValuesDeep } from '@/utils/deepdash';
import { mapValuesDeep } from '@/utils/deepdash';
@Injectable()
export class ToJsonInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(
map((data) => {
if (data === null || data === undefined) {
return data;
}
return mapValuesDeep(data, (value) => {
if (value && typeof value.toJSON === 'function') {
if (value !== null && value !== undefined && typeof value.toJSON === 'function') {
return value.toJSON();
}
return value;

View File

@@ -36,8 +36,8 @@ import { PdfTemplatesModule } from '../PdfTemplate/PdfTemplates.module';
import { BranchesModule } from '../Branches/Branches.module';
import { WarehousesModule } from '../Warehouses/Warehouses.module';
import { SerializeInterceptor } from '@/common/interceptors/serialize.interceptor';
import { ValidationPipe } from '@/common/pipes/ClassValidation.pipe';
import { ToJsonInterceptor } from '@/common/interceptors/to-json.interceptor';
import { ValidationPipe } from '@/common/pipes/ClassValidation.pipe';
import { ServiceErrorFilter } from '@/common/filters/service-error.filter';
import { ModelHasRelationsFilter } from '@/common/filters/model-has-relations.filter';
import { ChromiumlyTenancyModule } from '../ChromiumlyTenancy/ChromiumlyTenancy.module';
@@ -248,11 +248,11 @@ import { AppThrottleModule } from './AppThrottle.module';
},
{
provide: APP_INTERCEPTOR,
useClass: ToJsonInterceptor,
useClass: SerializeInterceptor,
},
{
provide: APP_INTERCEPTOR,
useClass: SerializeInterceptor,
useClass: ToJsonInterceptor,
},
{
provide: APP_INTERCEPTOR,