chore(repo): made ZodSerializerDto optional
This commit is contained in:
parent
60b1701d01
commit
b180968def
@ -11,6 +11,7 @@ import {
|
||||
SetMetadata,
|
||||
StreamableFile,
|
||||
} from '@nestjs/common';
|
||||
import { chain } from 'lodash';
|
||||
import { Observable, map } from 'rxjs';
|
||||
import { ZodSchema } from 'zod';
|
||||
|
||||
@ -34,7 +35,7 @@ export class ZodSerializerInterceptor implements NestInterceptor {
|
||||
}
|
||||
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||
const { dto: responseSchema } = this.getContextResponseSchema(context);
|
||||
const responseSchema = this.getContextResponseSchema(context);
|
||||
|
||||
return next.handle().pipe(
|
||||
map((res: object | object[]) => {
|
||||
@ -51,10 +52,21 @@ export class ZodSerializerInterceptor implements NestInterceptor {
|
||||
);
|
||||
}
|
||||
|
||||
protected getContextResponseSchema(context: ExecutionContext): {
|
||||
dto: ZodDtoStatic | ZodSchema | undefined;
|
||||
} {
|
||||
return this.reflector.getAllAndMerge('zodSerializedDtoOptions', [context.getHandler(), context.getClass()]);
|
||||
protected getContextResponseSchema(context: ExecutionContext): ZodDtoStatic | ZodSchema {
|
||||
const zodSerializedDto = (() => {
|
||||
const metadata = 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