feat(medusa): Modules initializer (#3352)
This commit is contained in:
committed by
GitHub
parent
8a7421db5b
commit
aa690beed7
@@ -4,16 +4,16 @@ export function MedusaContext() {
|
||||
propertyKey: string | symbol,
|
||||
parameterIndex: number
|
||||
) {
|
||||
if (!target.MedusaContext_) {
|
||||
target.MedusaContext_ = {}
|
||||
if (!target.MedusaContextIndex_) {
|
||||
target.MedusaContextIndex_ = {}
|
||||
}
|
||||
|
||||
if (propertyKey in target.MedusaContext_) {
|
||||
if (propertyKey in target.MedusaContextIndex_) {
|
||||
throw new Error(
|
||||
`Only one MedusaContext is allowed on method "${String(propertyKey)}".`
|
||||
)
|
||||
}
|
||||
|
||||
target.MedusaContext_[propertyKey] = parameterIndex
|
||||
target.MedusaContextIndex_[propertyKey] = parameterIndex
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export function InjectEntityManager(
|
||||
propertyKey: string | symbol,
|
||||
descriptor: any
|
||||
): void {
|
||||
if (!target.MedusaContext_) {
|
||||
if (!target.MedusaContextIndex_) {
|
||||
throw new Error(
|
||||
`To apply @InjectEntityManager you have to flag a parameter using @MedusaContext`
|
||||
)
|
||||
@@ -16,7 +16,7 @@ export function InjectEntityManager(
|
||||
|
||||
const originalMethod = descriptor.value
|
||||
|
||||
const argIndex = target.MedusaContext_[propertyKey]
|
||||
const argIndex = target.MedusaContextIndex_[propertyKey]
|
||||
descriptor.value = async function (...args: any[]) {
|
||||
const context: SharedContext = args[argIndex] ?? {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user