Skip to content

Commit 27a1321

Browse files
refactor(microservices): utilize shared utils at pattern decorators
1 parent 8a81f5e commit 27a1321

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

packages/microservices/decorators/event-pattern.decorator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '../constants';
77
import { PatternHandler } from '../enums/pattern-handler.enum';
88
import { Transport } from '../enums';
9+
import { isObject, isNumber, isNil } from '../../common/utils/shared.utils';
910

1011
/**
1112
* Subscribes to incoming events which fulfils chosen pattern.
@@ -26,9 +27,9 @@ export const EventPattern: {
2627
): MethodDecorator => {
2728
let transport: Transport;
2829
let extras: Record<string, any>;
29-
if (typeof arg1 === 'number' && !arg2) {
30+
if (isNumber(arg1) && isNil(arg2)) {
3031
transport = arg1;
31-
} else if (typeof arg1 === 'object' && arg1 !== null && !arg2) {
32+
} else if (isObject(arg1) && isNil(arg2)) {
3233
extras = arg1;
3334
} else {
3435
transport = arg1 as Transport;

packages/microservices/decorators/message-pattern.decorator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { PatternHandler } from '../enums/pattern-handler.enum';
99
import { PatternMetadata } from '../interfaces/pattern-metadata.interface';
1010
import { Transport } from '../enums';
11+
import { isObject, isNumber, isNil } from '../../common/utils/shared.utils';
1112

1213
export enum GrpcMethodStreamingType {
1314
NO_STREAMING = 'no_stream',
@@ -40,9 +41,9 @@ export const MessagePattern: {
4041
): MethodDecorator => {
4142
let transport: Transport;
4243
let extras: Record<string, any>;
43-
if (typeof arg1 === 'number' && !arg2) {
44+
if (isNumber(arg1) && isNil(arg2)) {
4445
transport = arg1;
45-
} else if (typeof arg1 === 'object' && arg1 !== null && !arg2) {
46+
} else if (isObject(arg1) && isNil(arg2)) {
4647
extras = arg1;
4748
} else {
4849
transport = arg1 as Transport;

0 commit comments

Comments
 (0)