feat(medusa): Modules initializer (#3352)

This commit is contained in:
Carlos R. L. Rodrigues
2023-03-17 12:18:52 -03:00
committed by GitHub
parent 8a7421db5b
commit aa690beed7
51 changed files with 1290 additions and 715 deletions

View File

@@ -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
}
}

View File

@@ -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] ?? {}