Skip to content

Commit

Permalink
refactor: Skip when the value is equal undefined/null
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdlrahmanSaberAbdo committed Jun 23, 2023
1 parent 9359160 commit 0b8f437
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/common/pipes/parse-enum.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ErrorHttpStatusCode,
HttpErrorByCode,
} from '../utils/http-error-by-code.util';
import { isNil } from '../utils/shared.utils';

/**
* @publicApi
Expand Down Expand Up @@ -51,7 +52,10 @@ export class ParseEnumPipe<T = any> implements PipeTransform<T> {
* @param metadata contains metadata about the currently processed route argument
*/
async transform(value: T, metadata: ArgumentMetadata): Promise<T> {
if (!this.options.optional && !this.isEnum(value)) {
if (isNil(value) && this.options.optional) {
return value;
}
if (!this.isEnum(value)) {
throw this.exceptionFactory(
'Validation failed (enum string is expected)',
);
Expand Down

0 comments on commit 0b8f437

Please sign in to comment.