chore(repo): made ZodSerializerDto optional
This commit is contained in:
parent
60b1701d01
commit
b180968def
@ -11,6 +11,7 @@ import {
|
|||||||
SetMetadata,
|
SetMetadata,
|
||||||
StreamableFile,
|
StreamableFile,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
import { chain } from 'lodash';
|
||||||
import { Observable, map } from 'rxjs';
|
import { Observable, map } from 'rxjs';
|
||||||
import { ZodSchema } from 'zod';
|
import { ZodSchema } from 'zod';
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ export class ZodSerializerInterceptor implements NestInterceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||||
const { dto: responseSchema } = this.getContextResponseSchema(context);
|
const responseSchema = this.getContextResponseSchema(context);
|
||||||
|
|
||||||
return next.handle().pipe(
|
return next.handle().pipe(
|
||||||
map((res: object | object[]) => {
|
map((res: object | object[]) => {
|
||||||
@ -51,10 +52,21 @@ export class ZodSerializerInterceptor implements NestInterceptor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getContextResponseSchema(context: ExecutionContext): {
|
protected getContextResponseSchema(context: ExecutionContext): ZodDtoStatic | ZodSchema {
|
||||||
dto: ZodDtoStatic | ZodSchema | undefined;
|
const zodSerializedDto = (() => {
|
||||||
} {
|
const metadata = this.reflector.getAllAndMerge('zodSerializedDtoOptions', [context.getHandler(), context.getClass()]);
|
||||||
return this.reflector.getAllAndMerge('zodSerializedDtoOptions', [context.getHandler(), context.getClass()]);
|
return metadata.dto;
|
||||||
|
})();
|
||||||
|
if (zodSerializedDto) return zodSerializedDto;
|
||||||
|
|
||||||
|
const swaggerApiResponseType = (() => {
|
||||||
|
const metadata = this.reflector.getAllAndMerge('swagger/apiResponse', [context.getHandler(), context.getClass()]);
|
||||||
|
const metadataForStatusCode = chain([metadata[HttpStatus.OK], metadata[HttpStatus.CREATED]]).filter(Boolean).first().value();
|
||||||
|
return metadataForStatusCode.type;
|
||||||
|
})();
|
||||||
|
if (swaggerApiResponseType) return swaggerApiResponseType;
|
||||||
|
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user