-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rabbitmq): Added a new decorator @RabbitHeader()
* feat(add_header_decorator): @RabbitHeader() decorator added now we can access provided headers inside consumers * fix(merged): branch merged with parent * fix(rabbit_header): index modified inside RabbitRpcParamsFactory * fix(namedconnectionmodule): rabbit uri changed to its default * fix(doc): emir muhammadzadeh added
- Loading branch information
1 parent
1d26ad5
commit b283945
Showing
5 changed files
with
97 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
import { ParamData } from '@nestjs/common'; | ||
import { isObject } from 'lodash'; | ||
import { RABBIT_PARAM_TYPE } from './rabbitmq.constants'; | ||
import { | ||
RABBIT_HEADER_TYPE, | ||
RABBIT_PARAM_TYPE, | ||
RABBIT_REQUEST_TYPE, | ||
} from './rabbitmq.constants'; | ||
|
||
export class RabbitRpcParamsFactory { | ||
public exchangeKeyForValue(type: number, data: ParamData, args: any[]) { | ||
if (!args || type !== RABBIT_PARAM_TYPE) { | ||
if (!args) { | ||
return null; | ||
} | ||
|
||
return data && !isObject(data) ? args[0]?.[data] : args[0]; | ||
let index = 0; | ||
if (type === RABBIT_PARAM_TYPE) { | ||
index = 0; | ||
} else if (type === RABBIT_REQUEST_TYPE) { | ||
index = 1; | ||
} else if (type === RABBIT_HEADER_TYPE) { | ||
index = 2; | ||
} | ||
|
||
return data && !isObject(data) ? args[index]?.[data] : args[index]; | ||
} | ||
} |