Chore/rm main entity concept (#7709)

**What**
Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate.
This pr also includes various fixes in different modules

Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2024-06-19 15:02:16 +02:00
committed by GitHub
parent 2895ccfba8
commit 48963f55ef
533 changed files with 6469 additions and 9769 deletions
@@ -1,10 +1,8 @@
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
import {
ICartModuleService,
ICustomerModuleService,
IFulfillmentModuleService,
IInventoryServiceNext,
IPaymentModuleService,
IPricingModuleService,
IProductModuleService,
IRegionModuleService,
@@ -31,14 +29,11 @@ medusaIntegrationTestRunner({
let cartModuleService: ICartModuleService
let regionModuleService: IRegionModuleService
let scModuleService: ISalesChannelModuleService
let customerModule: ICustomerModuleService
let productModule: IProductModuleService
let pricingModule: IPricingModuleService
let paymentModule: IPaymentModuleService
let inventoryModule: IInventoryServiceNext
let stockLocationModule: IStockLocationServiceNext
let fulfillmentModule: IFulfillmentModuleService
let locationModule: IStockLocationServiceNext
let taxModule: ITaxModuleService
let remoteLink, remoteQuery
@@ -49,10 +44,8 @@ medusaIntegrationTestRunner({
scModuleService = appContainer.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT)
pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING)
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
inventoryModule = appContainer.resolve(ModuleRegistrationName.INVENTORY)
stockLocationModule = appContainer.resolve(
ModuleRegistrationName.STOCK_LOCATION
@@ -60,9 +53,6 @@ medusaIntegrationTestRunner({
fulfillmentModule = appContainer.resolve(
ModuleRegistrationName.FULFILLMENT
)
locationModule = appContainer.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
taxModule = appContainer.resolve(ModuleRegistrationName.TAX)
remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
remoteQuery = appContainer.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
@@ -74,20 +64,20 @@ medusaIntegrationTestRunner({
describe("Draft Orders - Admin", () => {
it("should create a draft order", async () => {
const region = await regionModuleService.create({
const region = await regionModuleService.createRegions({
name: "US",
currency_code: "usd",
})
const salesChannel = await scModuleService.create({
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await stockLocationModule.create({
const location = await stockLocationModule.createStockLocations({
name: "Warehouse",
})
const [product, product_2] = await productModule.create([
const [product, product_2] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -107,7 +97,7 @@ medusaIntegrationTestRunner({
},
])
const inventoryItem = await inventoryModule.create({
const inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -120,7 +110,7 @@ medusaIntegrationTestRunner({
},
])
const [priceSet, priceSet_2] = await pricingModule.create([
const [priceSet, priceSet_2] = await pricingModule.createPriceSets([
{
prices: [
{
@@ -1,7 +1,6 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import {
ICartModuleService,
ICustomerModuleService,
IFulfillmentModuleService,
IInventoryServiceNext,
IOrderModuleService,
@@ -9,9 +8,7 @@ import {
IPricingModuleService,
IProductModuleService,
IRegionModuleService,
ISalesChannelModuleService,
IStockLocationServiceNext,
ITaxModuleService,
} from "@medusajs/types"
import { ContainerRegistrationKeys } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
@@ -30,16 +27,12 @@ medusaIntegrationTestRunner({
let appContainer
let cartModuleService: ICartModuleService
let regionModuleService: IRegionModuleService
let scModuleService: ISalesChannelModuleService
let customerModule: ICustomerModuleService
let productModule: IProductModuleService
let pricingModule: IPricingModuleService
let paymentModule: IPaymentModuleService
let pricingModule: IPricingModuleService
let inventoryModule: IInventoryServiceNext
let stockLocationModule: IStockLocationServiceNext
let fulfillmentModule: IFulfillmentModuleService
let locationModule: IStockLocationServiceNext
let taxModule: ITaxModuleService
let orderModule: IOrderModuleService
let remoteLink, remoteQuery
@@ -47,24 +40,12 @@ medusaIntegrationTestRunner({
appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
regionModuleService = appContainer.resolve(ModuleRegistrationName.REGION)
scModuleService = appContainer.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
customerModule = appContainer.resolve(ModuleRegistrationName.CUSTOMER)
productModule = appContainer.resolve(ModuleRegistrationName.PRODUCT)
pricingModule = appContainer.resolve(ModuleRegistrationName.PRICING)
paymentModule = appContainer.resolve(ModuleRegistrationName.PAYMENT)
inventoryModule = appContainer.resolve(ModuleRegistrationName.INVENTORY)
stockLocationModule = appContainer.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
fulfillmentModule = appContainer.resolve(
ModuleRegistrationName.FULFILLMENT
)
locationModule = appContainer.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
taxModule = appContainer.resolve(ModuleRegistrationName.TAX)
remoteLink = appContainer.resolve(ContainerRegistrationKeys.REMOTE_LINK)
remoteQuery = appContainer.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
orderModule = appContainer.resolve(ModuleRegistrationName.ORDER)
@@ -76,7 +57,7 @@ medusaIntegrationTestRunner({
describe("Orders - Admin", () => {
it("should get an order", async () => {
const created = await orderModule.create({
const created = await orderModule.createOrders({
region_id: "test_region_idclear",
email: "foo@bar.com",
items: [
@@ -9,7 +9,7 @@ import {
FulfillmentWorkflow,
IOrderModuleService,
IRegionModuleService,
IStockLocationServiceNext,
IStockLocationService,
OrderWorkflow,
ProductDTO,
RegionDTO,
@@ -35,7 +35,7 @@ async function prepareDataFixtures({ container }) {
const salesChannelService = container.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
const stockLocationModule: IStockLocationServiceNext = container.resolve(
const stockLocationModule: IStockLocationService = container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const productModule = container.resolve(ModuleRegistrationName.PRODUCT)
@@ -46,7 +46,7 @@ async function prepareDataFixtures({ container }) {
type: "default",
})
const fulfillmentSet = await fulfillmentService.create({
const fulfillmentSet = await fulfillmentService.createFulfillmentSets({
name: "Test fulfillment set",
type: "manual_test",
})
@@ -66,7 +66,7 @@ async function prepareDataFixtures({ container }) {
ModuleRegistrationName.REGION
) as IRegionModuleService
const [region] = await regionService.create([
const [region] = await regionService.createRegions([
{
name: "Test region",
currency_code: "eur",
@@ -74,22 +74,23 @@ async function prepareDataFixtures({ container }) {
},
])
const salesChannel = await salesChannelService.create({
const salesChannel = await salesChannelService.createSalesChannels({
name: "Webshop",
})
const location: StockLocationDTO = await stockLocationModule.create({
name: "Warehouse",
address: {
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
phone: "12345",
},
})
const location: StockLocationDTO =
await stockLocationModule.createStockLocations({
name: "Warehouse",
address: {
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
phone: "12345",
},
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -101,7 +102,7 @@ async function prepareDataFixtures({ container }) {
},
])
inventoryItem = await inventoryModule.create({
inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -210,7 +211,7 @@ async function createOrderFixture({ container, product, location }) {
const orderService: IOrderModuleService = container.resolve(
ModuleRegistrationName.ORDER
)
let order = await orderService.create({
let order = await orderService.createOrders({
region_id: "test_region_idclear",
email: "foo@bar.com",
items: [
@@ -292,7 +293,7 @@ async function createOrderFixture({ container, product, location }) {
},
])
order = await orderService.retrieve(order.id, {
order = await orderService.retrieveOrder(order.id, {
relations: ["items"],
})
@@ -8,7 +8,7 @@ import {
FulfillmentWorkflow,
IOrderModuleService,
IRegionModuleService,
IStockLocationServiceNext,
IStockLocationService,
OrderWorkflow,
ProductDTO,
RegionDTO,
@@ -34,7 +34,7 @@ async function prepareDataFixtures({ container }) {
const salesChannelService = container.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
const stockLocationModule: IStockLocationServiceNext = container.resolve(
const stockLocationModule: IStockLocationService = container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const productModule = container.resolve(ModuleRegistrationName.PRODUCT)
@@ -45,7 +45,7 @@ async function prepareDataFixtures({ container }) {
type: "default",
})
const fulfillmentSet = await fulfillmentService.create({
const fulfillmentSet = await fulfillmentService.createFulfillmentSets({
name: "Test fulfillment set",
type: "manual_test",
})
@@ -65,7 +65,7 @@ async function prepareDataFixtures({ container }) {
ModuleRegistrationName.REGION
) as IRegionModuleService
const [region] = await regionService.create([
const [region] = await regionService.createRegions([
{
name: "Test region",
currency_code: "eur",
@@ -73,22 +73,23 @@ async function prepareDataFixtures({ container }) {
},
])
const salesChannel = await salesChannelService.create({
const salesChannel = await salesChannelService.createSalesChannels({
name: "Webshop",
})
const location: StockLocationDTO = await stockLocationModule.create({
name: "Warehouse",
address: {
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
phone: "12345",
},
})
const location: StockLocationDTO =
await stockLocationModule.createStockLocations({
name: "Warehouse",
address: {
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
phone: "12345",
},
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -105,7 +106,7 @@ async function prepareDataFixtures({ container }) {
},
])
inventoryItem = await inventoryModule.create({
inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -214,7 +215,7 @@ async function createOrderFixture({ container, product, location }) {
const orderService: IOrderModuleService = container.resolve(
ModuleRegistrationName.ORDER
)
let order = await orderService.create({
let order = await orderService.createOrders({
region_id: "test_region_idclear",
email: "foo@bar.com",
items: [
@@ -305,7 +306,7 @@ async function createOrderFixture({ container, product, location }) {
},
])
order = await orderService.retrieve(order.id, {
order = await orderService.retrieveOrder(order.id, {
relations: ["items"],
})
@@ -12,7 +12,7 @@ import {
FulfillmentWorkflow,
IOrderModuleService,
IRegionModuleService,
IStockLocationServiceNext,
IStockLocationService,
OrderWorkflow,
ProductDTO,
RegionDTO,
@@ -21,8 +21,8 @@ import {
} from "@medusajs/types"
import {
ContainerRegistrationKeys,
RuleOperator,
remoteQueryObjectFromString,
RuleOperator,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
@@ -38,7 +38,7 @@ async function prepareDataFixtures({ container }) {
const salesChannelService = container.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
const stockLocationModule: IStockLocationServiceNext = container.resolve(
const stockLocationModule: IStockLocationService = container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const productModule = container.resolve(ModuleRegistrationName.PRODUCT)
@@ -49,7 +49,7 @@ async function prepareDataFixtures({ container }) {
type: "default",
})
const fulfillmentSet = await fulfillmentService.create({
const fulfillmentSet = await fulfillmentService.createFulfillmentSets({
name: "Test fulfillment set",
type: "manual_test",
})
@@ -69,7 +69,7 @@ async function prepareDataFixtures({ container }) {
ModuleRegistrationName.REGION
) as IRegionModuleService
const [region] = await regionService.create([
const [region] = await regionService.createRegions([
{
name: "Test region",
currency_code: "eur",
@@ -77,22 +77,23 @@ async function prepareDataFixtures({ container }) {
},
])
const salesChannel = await salesChannelService.create({
const salesChannel = await salesChannelService.createSalesChannels({
name: "Webshop",
})
const location: StockLocationDTO = await stockLocationModule.create({
name: "Warehouse",
address: {
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
phone: "12345",
},
})
const location: StockLocationDTO =
await stockLocationModule.createStockLocations({
name: "Warehouse",
address: {
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
phone: "12345",
},
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -104,7 +105,7 @@ async function prepareDataFixtures({ container }) {
},
])
const inventoryItem = await inventoryModule.create({
const inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -221,7 +222,7 @@ async function createOrderFixture({ container, product }) {
const orderService: IOrderModuleService = container.resolve(
ModuleRegistrationName.ORDER
)
let order = await orderService.create({
let order = await orderService.createOrders({
region_id: "test_region_idclear",
email: "foo@bar.com",
items: [
@@ -331,7 +332,7 @@ async function createOrderFixture({ container, product }) {
await orderService.applyPendingOrderActions(order.id)
order = await orderService.retrieve(order.id, {
order = await orderService.retrieveOrder(order.id, {
relations: ["items"],
})
@@ -8,7 +8,7 @@ import {
FulfillmentWorkflow,
IOrderModuleService,
IRegionModuleService,
IStockLocationServiceNext,
IStockLocationService,
OrderWorkflow,
ProductDTO,
RegionDTO,
@@ -17,8 +17,8 @@ import {
} from "@medusajs/types"
import {
ContainerRegistrationKeys,
RuleOperator,
remoteQueryObjectFromString,
RuleOperator,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
@@ -35,7 +35,7 @@ async function prepareDataFixtures({ container }) {
const salesChannelService = container.resolve(
ModuleRegistrationName.SALES_CHANNEL
)
const stockLocationModule: IStockLocationServiceNext = container.resolve(
const stockLocationModule: IStockLocationService = container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
const productModule = container.resolve(ModuleRegistrationName.PRODUCT)
@@ -46,7 +46,7 @@ async function prepareDataFixtures({ container }) {
type: "default",
})
const fulfillmentSet = await fulfillmentService.create({
const fulfillmentSet = await fulfillmentService.createFulfillmentSets({
name: "Test fulfillment set",
type: "manual_test",
})
@@ -66,7 +66,7 @@ async function prepareDataFixtures({ container }) {
ModuleRegistrationName.REGION
) as IRegionModuleService
const [region] = await regionService.create([
const [region] = await regionService.createRegions([
{
name: "Test region",
currency_code: "eur",
@@ -74,22 +74,23 @@ async function prepareDataFixtures({ container }) {
},
])
const salesChannel = await salesChannelService.create({
const salesChannel = await salesChannelService.createSalesChannels({
name: "Webshop",
})
const location: StockLocationDTO = await stockLocationModule.create({
name: "Warehouse",
address: {
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
phone: "12345",
},
})
const location: StockLocationDTO =
await stockLocationModule.createStockLocations({
name: "Warehouse",
address: {
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
phone: "12345",
},
})
const [product] = await productModule.create([
const [product] = await productModule.createProducts([
{
title: "Test product",
variants: [
@@ -101,7 +102,7 @@ async function prepareDataFixtures({ container }) {
},
])
inventoryItem = await inventoryModule.create({
inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
@@ -217,7 +218,7 @@ async function createOrderFixture({ container, product, location }) {
const orderService: IOrderModuleService = container.resolve(
ModuleRegistrationName.ORDER
)
let order = await orderService.create({
let order = await orderService.createOrders({
region_id: "test_region_idclear",
email: "foo@bar.com",
items: [
@@ -299,7 +300,7 @@ async function createOrderFixture({ container, product, location }) {
},
])
order = await orderService.retrieve(order.id, {
order = await orderService.retrieveOrder(order.id, {
relations: ["items"],
})