Merge pull request #907 from bigcapitalhq/feature/20260121130702

hotbug(server): interceptors order
This commit is contained in:
Ahmed Bouhuolia
2026-01-21 13:08:18 +02:00
committed by GitHub
2 changed files with 8 additions and 5 deletions

View File

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

View File

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