fix: Medusa service base method transaction (#7758)
**What** Remove transaction decorator from the base medusa service method, the transaction will always be coming from the shared context. It fixes the issue that when you consume a base method directly it will return a proper tuple from the DB instead of the one from the entity map cc @VariableVic **NOTE** This pr also fix some categories issues in the product module which was preventing the tests from working. if @sradevski you could have a look later, in the mean time we can still merge it FIXES CORE-2342
This commit is contained in:
committed by
GitHub
parent
8410592239
commit
e0b14519f1
@@ -9,7 +9,7 @@ const baseRepoMock = {
|
||||
const defaultContext = { __type: "MedusaContext", manager: baseRepoMock }
|
||||
const defaultTransactionContext = {
|
||||
__type: "MedusaContext",
|
||||
transactionManager: "transactionManager",
|
||||
manager: baseRepoMock,
|
||||
}
|
||||
|
||||
describe("Abstract Module Service Factory", () => {
|
||||
|
||||
@@ -20,11 +20,7 @@ import {
|
||||
pluralize,
|
||||
upperCaseFirst,
|
||||
} from "../common"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
} from "./decorators"
|
||||
import { InjectManager, MedusaContext } from "./decorators"
|
||||
import { ModuleRegistrationName } from "./definition"
|
||||
|
||||
type BaseMethods =
|
||||
@@ -384,11 +380,7 @@ export function MedusaService<
|
||||
|
||||
MedusaContext()(klassPrototype, methodName, contextIndex)
|
||||
|
||||
const ManagerDecorator = readMethods.includes(method as BaseMethods)
|
||||
? InjectManager
|
||||
: InjectTransactionManager
|
||||
|
||||
ManagerDecorator("baseRepository_")(
|
||||
InjectManager("baseRepository_")(
|
||||
klassPrototype,
|
||||
methodName,
|
||||
descriptorMockRef
|
||||
@@ -413,9 +405,7 @@ export function MedusaService<
|
||||
serviceRegistrationName
|
||||
].retrieve(id, config, sharedContext)
|
||||
|
||||
return await this.baseRepository_.serialize<T>(entities, {
|
||||
populate: true,
|
||||
})
|
||||
return await this.baseRepository_.serialize<T>(entities)
|
||||
}
|
||||
|
||||
applyMethod(methodImplementation, 2)
|
||||
@@ -432,9 +422,7 @@ export function MedusaService<
|
||||
const entities = await service.create(serviceData, sharedContext)
|
||||
const response = Array.isArray(data) ? entities : entities[0]
|
||||
|
||||
return await this.baseRepository_.serialize<T | T[]>(response, {
|
||||
populate: true,
|
||||
})
|
||||
return await this.baseRepository_.serialize<T | T[]>(response)
|
||||
}
|
||||
|
||||
applyMethod(methodImplementation, 1)
|
||||
@@ -451,9 +439,7 @@ export function MedusaService<
|
||||
const entities = await service.update(serviceData, sharedContext)
|
||||
const response = Array.isArray(data) ? entities : entities[0]
|
||||
|
||||
return await this.baseRepository_.serialize<T | T[]>(response, {
|
||||
populate: true,
|
||||
})
|
||||
return await this.baseRepository_.serialize<T | T[]>(response)
|
||||
}
|
||||
|
||||
applyMethod(methodImplementation, 1)
|
||||
@@ -469,9 +455,7 @@ export function MedusaService<
|
||||
const service = this.__container__[serviceRegistrationName]
|
||||
const entities = await service.list(filters, config, sharedContext)
|
||||
|
||||
return await this.baseRepository_.serialize<T[]>(entities, {
|
||||
populate: true,
|
||||
})
|
||||
return await this.baseRepository_.serialize<T[]>(entities)
|
||||
}
|
||||
|
||||
applyMethod(methodImplementation, 2)
|
||||
@@ -488,12 +472,7 @@ export function MedusaService<
|
||||
serviceRegistrationName
|
||||
].listAndCount(filters, config, sharedContext)
|
||||
|
||||
return [
|
||||
await this.baseRepository_.serialize<T[]>(entities, {
|
||||
populate: true,
|
||||
}),
|
||||
count,
|
||||
]
|
||||
return [await this.baseRepository_.serialize<T[]>(entities), count]
|
||||
}
|
||||
|
||||
applyMethod(methodImplementation, 2)
|
||||
@@ -542,10 +521,7 @@ export function MedusaService<
|
||||
].softDelete(primaryKeyValues_, sharedContext)
|
||||
|
||||
const softDeletedEntities = await this.baseRepository_.serialize<T[]>(
|
||||
entities,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
entities
|
||||
)
|
||||
|
||||
await this.eventBusModuleService_?.emit(
|
||||
|
||||
Reference in New Issue
Block a user