fix(medusa): Add module config to transaction base service (#3033)

This commit is contained in:
Oliver Windall Juhl authored and GitHub committed 2023-01-15 19:37:11 +01:00
1 parent 93d0dc1bdc
commit 1547dd8143
4 files changed
+41 -30

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
---
"@medusajs/inventory": patch
"@medusajs/medusa": patch
"@medusajs/stock-location": patch
---
fix(medusa): Add module options to transaction base service to use in modules
+18 -17
View File
@@ -1,30 +1,30 @@
import { MedusaError } from "medusa-core-utils"
import { import {
FindConfig, ConfigurableModuleDeclaration,
IInventoryService,
FilterableInventoryItemProps,
FilterableReservationItemProps,
CreateInventoryItemInput, CreateInventoryItemInput,
CreateReservationItemInput,
FilterableInventoryLevelProps,
CreateInventoryLevelInput, CreateInventoryLevelInput,
CreateReservationItemInput,
FilterableInventoryItemProps,
FilterableInventoryLevelProps,
FilterableReservationItemProps,
FindConfig,
IEventBusService,
IInventoryService,
InventoryItemDTO,
InventoryLevelDTO,
MODULE_RESOURCE_TYPE,
ReservationItemDTO,
TransactionBaseService,
UpdateInventoryLevelInput, UpdateInventoryLevelInput,
UpdateReservationItemInput, UpdateReservationItemInput,
IEventBusService,
InventoryItemDTO,
ReservationItemDTO,
InventoryLevelDTO,
TransactionBaseService,
ConfigurableModuleDeclaration,
MODULE_RESOURCE_TYPE,
} from "@medusajs/medusa" } from "@medusajs/medusa"
import { MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import { import {
InventoryItemService, InventoryItemService,
ReservationItemService,
InventoryLevelService, InventoryLevelService,
ReservationItemService,
} from "./" } from "./"
import { EntityManager } from "typeorm"
type InjectedDependencies = { type InjectedDependencies = {
manager: EntityManager manager: EntityManager
@@ -47,7 +47,8 @@ export default class InventoryService
options?: unknown, options?: unknown,
moduleDeclaration?: ConfigurableModuleDeclaration moduleDeclaration?: ConfigurableModuleDeclaration
) { ) {
super(arguments[0]) // @ts-ignore
super(...arguments)
if (moduleDeclaration?.resources !== MODULE_RESOURCE_TYPE.SHARED) { if (moduleDeclaration?.resources !== MODULE_RESOURCE_TYPE.SHARED) {
throw new MedusaError( throw new MedusaError(
@@ -7,7 +7,8 @@ export abstract class TransactionBaseService {
protected constructor( protected constructor(
protected readonly __container__: any, protected readonly __container__: any,
protected readonly __configModule__?: Record<string, unknown> protected readonly __configModule__?: Record<string, unknown>,
protected readonly __moduleDeclaration__?: Record<string, unknown>
) {} ) {}
withTransaction(transactionManager?: EntityManager): this { withTransaction(transactionManager?: EntityManager): this {
@@ -17,7 +18,8 @@ export abstract class TransactionBaseService {
const cloned = new (this.constructor as any)( const cloned = new (this.constructor as any)(
this.__container__, this.__container__,
this.__configModule__ this.__configModule__,
this.__moduleDeclaration__
) )
cloned.manager_ = transactionManager cloned.manager_ = transactionManager
@@ -1,18 +1,18 @@
import { EntityManager } from "typeorm"
import { isDefined, MedusaError } from "medusa-core-utils"
import { import {
FindConfig,
buildQuery, buildQuery,
FilterableStockLocationProps,
CreateStockLocationInput,
UpdateStockLocationInput,
StockLocationAddressInput,
IEventBusService,
setMetadata,
TransactionBaseService,
ConfigurableModuleDeclaration, ConfigurableModuleDeclaration,
CreateStockLocationInput,
FilterableStockLocationProps,
FindConfig,
IEventBusService,
MODULE_RESOURCE_TYPE, MODULE_RESOURCE_TYPE,
setMetadata,
StockLocationAddressInput,
TransactionBaseService,
UpdateStockLocationInput,
} from "@medusajs/medusa" } from "@medusajs/medusa"
import { isDefined, MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import { StockLocation, StockLocationAddress } from "../models" import { StockLocation, StockLocationAddress } from "../models"
@@ -42,7 +42,8 @@ export default class StockLocationService extends TransactionBaseService {
options?: unknown, options?: unknown,
moduleDeclaration?: ConfigurableModuleDeclaration moduleDeclaration?: ConfigurableModuleDeclaration
) { ) {
super(arguments[0]) // @ts-ignore
super(...arguments)
if (moduleDeclaration?.resources !== MODULE_RESOURCE_TYPE.SHARED) { if (moduleDeclaration?.resources !== MODULE_RESOURCE_TYPE.SHARED) {
throw new MedusaError( throw new MedusaError(