chore: Abstract module service (#6188)
**What**
- Remove services that do not have any custom business and replace them with a simple interfaces
- Abstract module service provide the following base implementation
- retrieve
- list
- listAndCount
- delete
- softDelete
- restore
The above methods are created for the main model and also for each other models for which a config is provided
all method such as list, listAndCount, delete, softDelete and restore are pluralized with the model it refers to
**Migration**
- [x] product
- [x] pricing
- [x] promotion
- [x] cart
- [x] auth
- [x] customer
- [x] payment
- [x] Sales channel
- [x] Workflow-*
**Usage**
**Module**
The module service can now extend the ` ModulesSdkUtils.abstractModuleServiceFactory` which returns a class with the default implementation for each method and each model following the standard naming convention mentioned above.
This factory have 3 template arguments being the container, the main model DTO and an object representing the other model with a config object that contains at list the DTO and optionally a singular and plural property in case it needs to be set manually. It looks like the following:
```ts
export default class PricingModuleService</* ... */>
extends ModulesSdkUtils.abstractModuleServiceFactory<
InjectedDependencies,
PricingTypes.PriceSetDTO,
{
Currency: { dto: PricingTypes.CurrencyDTO }
MoneyAmount: { dto: PricingTypes.MoneyAmountDTO }
PriceSetMoneyAmount: { dto: PricingTypes.PriceSetMoneyAmountDTO }
PriceSetMoneyAmountRules: {
dto: PricingTypes.PriceSetMoneyAmountRulesDTO
}
PriceRule: { dto: PricingTypes.PriceRuleDTO }
RuleType: { dto: PricingTypes.RuleTypeDTO }
PriceList: { dto: PricingTypes.PriceListDTO }
PriceListRule: { dto: PricingTypes.PriceListRuleDTO }
}
>(PriceSet, generateMethodForModels, entityNameToLinkableKeysMap)
implements PricingTypes.IPricingModuleService
{
// ...
}
```
In the above, the singular and plural can be inferred as there is no tricky naming. Also, the default implementation does not remove the fact that you need to provides all the overloads etc in your module service interface. The above will provide a default implementation following the interface `AbstractModuleService` which is also auto generated, hence you will have the following methods available:
**for the main model**
- list
- retrieve
- listAndCount
- delete
- softDelete
- restore
**for the other models**
- list**MyModels**
- retrieve**MyModel**
- listAndCount**MyModels**
- delete**MyModels**
- softDelete**MyModels**
- restore**MyModels**
**Internal module service**
The internal module service can now extend `ModulesSdkUtils.internalModuleServiceFactory` which takes only one template argument which is the container type.
All internal services provides a default implementation for all retrieve, list, listAndCount, create, update, delete, softDelete, restore methods which follow the following interface `ModulesSdkTypes.InternalModuleService`:
```ts
export interface InternalModuleService<
TEntity extends {},
TContainer extends object = object
> {
get __container__(): TContainer
retrieve(
idOrObject: string,
config?: FindConfig<any>,
sharedContext?: Context
): Promise<TEntity>
retrieve(
idOrObject: object,
config?: FindConfig<any>,
sharedContext?: Context
): Promise<TEntity>
list(
filters?: FilterQuery<any> | BaseFilterable<FilterQuery<any>>,
config?: FindConfig<any>,
sharedContext?: Context
): Promise<TEntity[]>
listAndCount(
filters?: FilterQuery<any> | BaseFilterable<FilterQuery<any>>,
config?: FindConfig<any>,
sharedContext?: Context
): Promise<[TEntity[], number]>
create(data: any[], sharedContext?: Context): Promise<TEntity[]>
create(data: any, sharedContext?: Context): Promise<TEntity>
update(data: any[], sharedContext?: Context): Promise<TEntity[]>
update(data: any, sharedContext?: Context): Promise<TEntity>
update(
selectorAndData: {
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
data: any
},
sharedContext?: Context
): Promise<TEntity[]>
update(
selectorAndData: {
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
data: any
}[],
sharedContext?: Context
): Promise<TEntity[]>
delete(idOrSelector: string, sharedContext?: Context): Promise<void>
delete(idOrSelector: string[], sharedContext?: Context): Promise<void>
delete(idOrSelector: object, sharedContext?: Context): Promise<void>
delete(idOrSelector: object[], sharedContext?: Context): Promise<void>
delete(
idOrSelector: {
selector: FilterQuery<any> | BaseFilterable<FilterQuery<any>>
},
sharedContext?: Context
): Promise<void>
softDelete(
idsOrFilter: string[] | InternalFilterQuery,
sharedContext?: Context
): Promise<[TEntity[], Record<string, unknown[]>]>
restore(
idsOrFilter: string[] | InternalFilterQuery,
sharedContext?: Context
): Promise<[TEntity[], Record<string, unknown[]>]>
upsert(data: any[], sharedContext?: Context): Promise<TEntity[]>
upsert(data: any, sharedContext?: Context): Promise<TEntity>
}
```
When a service is auto generated you can use that interface to type your class property representing the expected internal service.
**Repositories**
The repositories can now extend `DALUtils.mikroOrmBaseRepositoryFactory` which takes one template argument being the entity or the template entity and provides all the default implementation. If the repository is auto generated you can type it using the `RepositoryService` interface. Here is the new interface typings.
```ts
export interface RepositoryService<T = any> extends BaseRepositoryService<T> {
find(options?: FindOptions<T>, context?: Context): Promise<T[]>
findAndCount(
options?: FindOptions<T>,
context?: Context
): Promise<[T[], number]>
create(data: any[], context?: Context): Promise<T[]>
// Becareful here, if you have a custom internal service, the update data should never be the entity otherwise
// both entity and update will point to the same ref and create issues with mikro orm
update(data: { entity; update }[], context?: Context): Promise<T[]>
delete(
idsOrPKs: FilterQuery<T> & BaseFilterable<FilterQuery<T>>,
context?: Context
): Promise<void>
/**
* Soft delete entities and cascade to related entities if configured.
*
* @param idsOrFilter
* @param context
*
* @returns [T[], Record<string, string[]>] the second value being the map of the entity names and ids that were soft deleted
*/
softDelete(
idsOrFilter: string[] | InternalFilterQuery,
context?: Context
): Promise<[T[], Record<string, unknown[]>]>
restore(
idsOrFilter: string[] | InternalFilterQuery,
context?: Context
): Promise<[T[], Record<string, unknown[]>]>
upsert(data: any[], context?: Context): Promise<T[]>
}
```
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { Address } from "@models"
|
||||
import { CreateAddressDTO, UpdateAddressDTO } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
addressRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class AddressService<
|
||||
TEntity extends Address = Address
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: CreateAddressDTO
|
||||
update: UpdateAddressDTO
|
||||
}
|
||||
>(Address)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,22 @@ import {
|
||||
Context,
|
||||
DAL,
|
||||
FilterableLineItemTaxLineProps,
|
||||
FindConfig,
|
||||
ICartModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
isObject,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
Address,
|
||||
Cart,
|
||||
LineItem,
|
||||
LineItemAdjustment,
|
||||
@@ -25,32 +27,73 @@ import {
|
||||
ShippingMethodAdjustment,
|
||||
ShippingMethodTaxLine,
|
||||
} from "@models"
|
||||
import { CreateLineItemDTO, UpdateLineItemDTO } from "@types"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import * as services from "../services"
|
||||
import {
|
||||
CreateLineItemDTO,
|
||||
CreateLineItemTaxLineDTO,
|
||||
CreateShippingMethodDTO,
|
||||
CreateShippingMethodTaxLineDTO,
|
||||
UpdateLineItemDTO,
|
||||
UpdateLineItemTaxLineDTO,
|
||||
UpdateShippingMethodTaxLineDTO,
|
||||
} from "@types"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
cartService: services.CartService
|
||||
addressService: services.AddressService
|
||||
lineItemService: services.LineItemService
|
||||
shippingMethodAdjustmentService: services.ShippingMethodAdjustmentService
|
||||
shippingMethodService: services.ShippingMethodService
|
||||
lineItemAdjustmentService: services.LineItemAdjustmentService
|
||||
lineItemTaxLineService: services.LineItemTaxLineService
|
||||
shippingMethodTaxLineService: services.ShippingMethodTaxLineService
|
||||
cartService: ModulesSdkTypes.InternalModuleService<any>
|
||||
addressService: ModulesSdkTypes.InternalModuleService<any>
|
||||
lineItemService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingMethodAdjustmentService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingMethodService: ModulesSdkTypes.InternalModuleService<any>
|
||||
lineItemAdjustmentService: ModulesSdkTypes.InternalModuleService<any>
|
||||
lineItemTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
||||
shippingMethodTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
||||
}
|
||||
|
||||
export default class CartModuleService implements ICartModuleService {
|
||||
const generateMethodForModels = [
|
||||
Address,
|
||||
LineItem,
|
||||
LineItemAdjustment,
|
||||
LineItemTaxLine,
|
||||
ShippingMethod,
|
||||
ShippingMethodAdjustment,
|
||||
ShippingMethodTaxLine,
|
||||
]
|
||||
|
||||
export default class CartModuleService<
|
||||
TCart extends Cart = Cart,
|
||||
TAddress extends Address = Address,
|
||||
TLineItem extends LineItem = LineItem,
|
||||
TLineItemAdjustment extends LineItemAdjustment = LineItemAdjustment,
|
||||
TLineItemTaxLine extends LineItemTaxLine = LineItemTaxLine,
|
||||
TShippingMethodAdjustment extends ShippingMethodAdjustment = ShippingMethodAdjustment,
|
||||
TShippingMethodTaxLine extends ShippingMethodTaxLine = ShippingMethodTaxLine,
|
||||
TShippingMethod extends ShippingMethod = ShippingMethod
|
||||
>
|
||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||
InjectedDependencies,
|
||||
CartTypes.CartDTO,
|
||||
{
|
||||
Address: { dto: CartTypes.CartAddressDTO }
|
||||
LineItem: { dto: CartTypes.CartLineItemDTO }
|
||||
LineItemAdjustment: { dto: CartTypes.LineItemAdjustmentDTO }
|
||||
LineItemTaxLine: { dto: CartTypes.LineItemTaxLineDTO }
|
||||
ShippingMethod: { dto: CartTypes.CartShippingMethodDTO }
|
||||
ShippingMethodAdjustment: { dto: CartTypes.ShippingMethodAdjustmentDTO }
|
||||
ShippingMethodTaxLine: { dto: CartTypes.ShippingMethodTaxLineDTO }
|
||||
}
|
||||
>(Cart, generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
implements ICartModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected cartService_: services.CartService
|
||||
protected addressService_: services.AddressService
|
||||
protected lineItemService_: services.LineItemService
|
||||
protected shippingMethodAdjustmentService_: services.ShippingMethodAdjustmentService
|
||||
protected shippingMethodService_: services.ShippingMethodService
|
||||
protected lineItemAdjustmentService_: services.LineItemAdjustmentService
|
||||
protected lineItemTaxLineService_: services.LineItemTaxLineService
|
||||
protected shippingMethodTaxLineService_: services.ShippingMethodTaxLineService
|
||||
protected cartService_: ModulesSdkTypes.InternalModuleService<TCart>
|
||||
protected addressService_: ModulesSdkTypes.InternalModuleService<TAddress>
|
||||
protected lineItemService_: ModulesSdkTypes.InternalModuleService<TLineItem>
|
||||
protected shippingMethodAdjustmentService_: ModulesSdkTypes.InternalModuleService<TShippingMethodAdjustment>
|
||||
protected shippingMethodService_: ModulesSdkTypes.InternalModuleService<TShippingMethod>
|
||||
protected lineItemAdjustmentService_: ModulesSdkTypes.InternalModuleService<TLineItemAdjustment>
|
||||
protected lineItemTaxLineService_: ModulesSdkTypes.InternalModuleService<TLineItemTaxLine>
|
||||
protected shippingMethodTaxLineService_: ModulesSdkTypes.InternalModuleService<TShippingMethodTaxLine>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -66,6 +109,9 @@ export default class CartModuleService implements ICartModuleService {
|
||||
}: InjectedDependencies,
|
||||
protected readonly moduleDeclaration: InternalModuleDeclaration
|
||||
) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
|
||||
this.baseRepository_ = baseRepository
|
||||
this.cartService_ = cartService
|
||||
this.addressService_ = addressService
|
||||
@@ -81,52 +127,6 @@ export default class CartModuleService implements ICartModuleService {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async retrieve(
|
||||
id: string,
|
||||
config: FindConfig<CartTypes.CartDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.CartDTO> {
|
||||
const cart = await this.cartService_.retrieve(id, config, sharedContext)
|
||||
|
||||
return await this.baseRepository_.serialize<CartTypes.CartDTO>(cart, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async list(
|
||||
filters: CartTypes.FilterableCartProps = {},
|
||||
config: FindConfig<CartTypes.CartDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.CartDTO[]> {
|
||||
const carts = await this.cartService_.list(filters, config, sharedContext)
|
||||
|
||||
return this.baseRepository_.serialize<CartTypes.CartDTO[]>(carts, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listAndCount(
|
||||
filters: CartTypes.FilterableCartProps = {},
|
||||
config: FindConfig<CartTypes.CartDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[CartTypes.CartDTO[], number]> {
|
||||
const [carts, count] = await this.cartService_.listAndCount(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return [
|
||||
await this.baseRepository_.serialize<CartTypes.CartDTO[]>(carts, {
|
||||
populate: true,
|
||||
}),
|
||||
count,
|
||||
]
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CartTypes.CreateCartDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -229,98 +229,6 @@ export default class CartModuleService implements ICartModuleService {
|
||||
return await this.cartService_.update(data, sharedContext)
|
||||
}
|
||||
|
||||
async delete(ids: string[], sharedContext?: Context): Promise<void>
|
||||
|
||||
async delete(ids: string, sharedContext?: Context): Promise<void>
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async delete(
|
||||
ids: string[] | string,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
const cartIds = Array.isArray(ids) ? ids : [ids]
|
||||
await this.cartService_.delete(cartIds, sharedContext)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listAddresses(
|
||||
filters: CartTypes.FilterableAddressProps = {},
|
||||
config: FindConfig<CartTypes.CartAddressDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
const addresses = await this.addressService_.list(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<CartTypes.CartAddressDTO[]>(
|
||||
addresses,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async retrieveLineItem(
|
||||
itemId: string,
|
||||
config: FindConfig<CartTypes.CartLineItemDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.CartLineItemDTO> {
|
||||
const item = await this.lineItemService_.retrieve(
|
||||
itemId,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<CartTypes.CartLineItemDTO>(
|
||||
item,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listLineItems(
|
||||
filters: CartTypes.FilterableLineItemProps = {},
|
||||
config: FindConfig<CartTypes.CartLineItemDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
const items = await this.lineItemService_.list(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<CartTypes.CartLineItemDTO[]>(
|
||||
items,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listShippingMethods(
|
||||
filters: CartTypes.FilterableShippingMethodProps = {},
|
||||
config: FindConfig<CartTypes.CartShippingMethodDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.CartShippingMethodDTO[]> {
|
||||
const methods = await this.shippingMethodService_.list(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<
|
||||
CartTypes.CartShippingMethodDTO[]
|
||||
>(methods, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
|
||||
addLineItems(
|
||||
data: CartTypes.CreateLineItemForCartDTO
|
||||
): Promise<CartTypes.CartLineItemDTO[]>
|
||||
@@ -585,18 +493,6 @@ export default class CartModuleService implements ICartModuleService {
|
||||
return await this.addressService_.update(data, sharedContext)
|
||||
}
|
||||
|
||||
async deleteAddresses(ids: string[], sharedContext?: Context): Promise<void>
|
||||
async deleteAddresses(ids: string, sharedContext?: Context): Promise<void>
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async deleteAddresses(
|
||||
ids: string[] | string,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
const addressIds = Array.isArray(ids) ? ids : [ids]
|
||||
await this.addressService_.delete(addressIds, sharedContext)
|
||||
}
|
||||
|
||||
async addShippingMethods(
|
||||
data: CartTypes.CreateShippingMethodDTO
|
||||
): Promise<CartTypes.CartShippingMethodDTO>
|
||||
@@ -665,7 +561,10 @@ export default class CartModuleService implements ICartModuleService {
|
||||
data: CartTypes.CreateShippingMethodDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ShippingMethod[]> {
|
||||
return await this.shippingMethodService_.create(data, sharedContext)
|
||||
return await this.shippingMethodService_.create(
|
||||
data as unknown as CreateShippingMethodDTO[],
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
async removeShippingMethods(
|
||||
@@ -708,25 +607,6 @@ export default class CartModuleService implements ICartModuleService {
|
||||
await this.shippingMethodService_.delete(toDelete, sharedContext)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listLineItemAdjustments(
|
||||
filters: CartTypes.FilterableLineItemAdjustmentProps = {},
|
||||
config: FindConfig<CartTypes.LineItemAdjustmentDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
const adjustments = await this.lineItemAdjustmentService_.list(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<
|
||||
CartTypes.LineItemAdjustmentDTO[]
|
||||
>(adjustments, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
|
||||
async addLineItemAdjustments(
|
||||
adjustments: CartTypes.CreateLineItemAdjustmentDTO[]
|
||||
): Promise<CartTypes.LineItemAdjustmentDTO[]>
|
||||
@@ -882,25 +762,6 @@ export default class CartModuleService implements ICartModuleService {
|
||||
await this.lineItemAdjustmentService_.delete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listShippingMethodAdjustments(
|
||||
filters: CartTypes.FilterableShippingMethodAdjustmentProps = {},
|
||||
config: FindConfig<CartTypes.ShippingMethodAdjustmentDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
const adjustments = await this.shippingMethodAdjustmentService_.list(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<
|
||||
CartTypes.ShippingMethodAdjustmentDTO[]
|
||||
>(adjustments, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async setShippingMethodAdjustments(
|
||||
cartId: string,
|
||||
@@ -1070,26 +931,6 @@ export default class CartModuleService implements ICartModuleService {
|
||||
await this.shippingMethodAdjustmentService_.delete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listLineItemTaxLines(
|
||||
filters: CartTypes.FilterableLineItemTaxLineProps = {},
|
||||
config: FindConfig<CartTypes.LineItemTaxLineDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
const taxLines = await this.lineItemTaxLineService_.list(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<CartTypes.LineItemTaxLineDTO[]>(
|
||||
taxLines,
|
||||
{
|
||||
populate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
addLineItemTaxLines(
|
||||
taxLines: CartTypes.CreateLineItemTaxLineDTO[]
|
||||
): Promise<CartTypes.LineItemTaxLineDTO[]>
|
||||
@@ -1123,14 +964,14 @@ export default class CartModuleService implements ICartModuleService {
|
||||
const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
|
||||
|
||||
addedTaxLines = await this.lineItemTaxLineService_.create(
|
||||
lines as CartTypes.CreateLineItemTaxLineDTO[],
|
||||
lines as CreateLineItemTaxLineDTO[],
|
||||
sharedContext
|
||||
)
|
||||
} else {
|
||||
const data = Array.isArray(cartIdOrData) ? cartIdOrData : [cartIdOrData]
|
||||
|
||||
addedTaxLines = await this.lineItemTaxLineService_.create(
|
||||
data as CartTypes.CreateLineItemTaxLineDTO[],
|
||||
data as CreateLineItemTaxLineDTO[],
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
@@ -1184,13 +1025,15 @@ export default class CartModuleService implements ICartModuleService {
|
||||
}
|
||||
})
|
||||
|
||||
await this.lineItemTaxLineService_.delete(
|
||||
toDelete.map((taxLine) => taxLine!.id),
|
||||
sharedContext
|
||||
)
|
||||
if (toDelete.length) {
|
||||
await this.lineItemTaxLineService_.delete(
|
||||
toDelete.map((taxLine) => taxLine!.id),
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
|
||||
const result = await this.lineItemTaxLineService_.upsert(
|
||||
taxLines,
|
||||
taxLines as UpdateLineItemTaxLineDTO[],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
@@ -1242,25 +1085,6 @@ export default class CartModuleService implements ICartModuleService {
|
||||
await this.lineItemTaxLineService_.delete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async listShippingMethodTaxLines(
|
||||
filters: CartTypes.FilterableShippingMethodTaxLineProps = {},
|
||||
config: FindConfig<CartTypes.ShippingMethodTaxLineDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
const taxLines = await this.shippingMethodTaxLineService_.list(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return await this.baseRepository_.serialize<
|
||||
CartTypes.ShippingMethodTaxLineDTO[]
|
||||
>(taxLines, {
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
|
||||
addShippingMethodTaxLines(
|
||||
taxLines: CartTypes.CreateShippingMethodTaxLineDTO[]
|
||||
): Promise<CartTypes.ShippingMethodTaxLineDTO[]>
|
||||
@@ -1296,12 +1120,12 @@ export default class CartModuleService implements ICartModuleService {
|
||||
const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
|
||||
|
||||
addedTaxLines = await this.shippingMethodTaxLineService_.create(
|
||||
lines as CartTypes.CreateShippingMethodTaxLineDTO[],
|
||||
lines as CreateShippingMethodTaxLineDTO[],
|
||||
sharedContext
|
||||
)
|
||||
} else {
|
||||
addedTaxLines = await this.shippingMethodTaxLineService_.create(
|
||||
taxLines as CartTypes.CreateShippingMethodTaxLineDTO[],
|
||||
taxLines as CreateShippingMethodTaxLineDTO[],
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
@@ -1367,7 +1191,7 @@ export default class CartModuleService implements ICartModuleService {
|
||||
}
|
||||
|
||||
const result = await this.shippingMethodTaxLineService_.upsert(
|
||||
taxLines,
|
||||
taxLines as UpdateShippingMethodTaxLineDTO[],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { Cart } from "@models"
|
||||
import { CreateCartDTO, UpdateCartDTO } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
cartRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class CartService<
|
||||
TEntity extends Cart = Cart
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: CreateCartDTO
|
||||
update: UpdateCartDTO
|
||||
}
|
||||
>(Cart)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1 @@
|
||||
export { default as AddressService } from "./address"
|
||||
export { default as CartService } from "./cart"
|
||||
export { default as CartModuleService } from "./cart-module"
|
||||
export { default as LineItemService } from "./line-item"
|
||||
export { default as LineItemAdjustmentService } from "./line-item-adjustment"
|
||||
export { default as LineItemTaxLineService } from "./line-item-tax-line"
|
||||
export { default as ShippingMethodService } from "./shipping-method"
|
||||
export { default as ShippingMethodAdjustmentService } from "./shipping-method-adjustment"
|
||||
export { default as ShippingMethodTaxLineService } from "./shipping-method-tax-line"
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { LineItemAdjustment } from "@models"
|
||||
import {
|
||||
CreateLineItemAdjustmentDTO,
|
||||
UpdateLineItemAdjustmentDTO,
|
||||
} from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
lineItemAdjustmentRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class LineItemAdjustmentService<
|
||||
TEntity extends LineItemAdjustment = LineItemAdjustment
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: CreateLineItemAdjustmentDTO
|
||||
update: UpdateLineItemAdjustmentDTO
|
||||
}
|
||||
>(LineItemAdjustment)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import {
|
||||
CreateLineItemTaxLineDTO,
|
||||
DAL,
|
||||
UpdateLineItemTaxLineDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { LineItemTaxLine } from "@models"
|
||||
|
||||
type InjectedDependencies = {
|
||||
lineItemTaxLineRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class LineItemTaxLineService<
|
||||
TEntity extends LineItemTaxLine = LineItemTaxLine
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: CreateLineItemTaxLineDTO
|
||||
update: UpdateLineItemTaxLineDTO
|
||||
}
|
||||
>(LineItemTaxLine)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { LineItem } from "@models"
|
||||
import { CreateLineItemDTO, UpdateLineItemDTO } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
lineItemRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class LineItemService<
|
||||
TEntity extends LineItem = LineItem
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: CreateLineItemDTO
|
||||
update: UpdateLineItemDTO
|
||||
}
|
||||
>(LineItem)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { ShippingMethodAdjustment } from "@models"
|
||||
import {
|
||||
CreateShippingMethodAdjustmentDTO,
|
||||
UpdateShippingMethodAdjustmentDTO,
|
||||
} from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
shippingMethodAdjustmentRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class ShippingMethodAdjustmentService<
|
||||
TEntity extends ShippingMethodAdjustment = ShippingMethodAdjustment
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: CreateShippingMethodAdjustmentDTO
|
||||
update: UpdateShippingMethodAdjustmentDTO
|
||||
}
|
||||
>(ShippingMethodAdjustment)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { CreateShippingMethodTaxLineDTO, DAL, UpdateShippingMethodTaxLineDTO } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { ShippingMethodTaxLine } from "@models"
|
||||
|
||||
type InjectedDependencies = {
|
||||
shippingMethodTaxLineRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class ShippingMethodTaxLineService<
|
||||
TEntity extends ShippingMethodTaxLine = ShippingMethodTaxLine
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: CreateShippingMethodTaxLineDTO
|
||||
update: UpdateShippingMethodTaxLineDTO
|
||||
}
|
||||
>(ShippingMethodTaxLine)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { ShippingMethod } from "@models"
|
||||
import { CreateShippingMethodDTO, UpdateShippingMethodDTO } from "../types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
shippingMethodRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class ShippingMethodService<
|
||||
TEntity extends ShippingMethod = ShippingMethod
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: CreateShippingMethodDTO
|
||||
update: UpdateShippingMethodDTO
|
||||
}
|
||||
>(ShippingMethod)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user