chore: Abstract module services (#6087)
**What** Create a service abstraction for the modules internal service layer. The objective is to reduce the effort of building new modules when the logic is the same or otherwise allow to override the default behavior. Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Oli Juhl
parent
80feb972cb
commit
130c641e5c
@@ -1,6 +1,14 @@
|
||||
import { Currency } from "@models"
|
||||
import { CurrencyService } from "@services"
|
||||
import { asClass, asValue, createContainer } from "awilix"
|
||||
|
||||
;(Currency as any).meta = {
|
||||
/**
|
||||
* Need to mock the Currency model as well to expose the primary keys when it is different than `id`
|
||||
*/
|
||||
primaryKeys: ["code"],
|
||||
}
|
||||
|
||||
export const nonExistingCurrencyCode = "non-existing-code"
|
||||
export const mockContainer = createContainer()
|
||||
|
||||
|
||||
@@ -1,106 +1,23 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { Currency } from "@models"
|
||||
import { CurrencyRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
currencyRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
protected readonly currencyRepository_: DAL.RepositoryService
|
||||
|
||||
export default class CurrencyService<
|
||||
TEntity extends Currency = Currency
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreateCurrencyDTO
|
||||
update: ServiceTypes.UpdateCurrencyDTO
|
||||
}
|
||||
>(Currency)<TEntity> {
|
||||
constructor({ currencyRepository }: InjectedDependencies) {
|
||||
this.currencyRepository_ = currencyRepository
|
||||
}
|
||||
|
||||
@InjectManager("currencyRepository_")
|
||||
async retrieve(
|
||||
currencyCode: string,
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<Currency, ServiceTypes.CurrencyDTO>({
|
||||
id: currencyCode,
|
||||
identifierColumn: "code",
|
||||
entityName: Currency.name,
|
||||
repository: this.currencyRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("currencyRepository_")
|
||||
async list(
|
||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.currencyRepository_.find(
|
||||
this.buildQueryForList(filters, config),
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectManager("currencyRepository_")
|
||||
async listAndCount(
|
||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.currencyRepository_.findAndCount(
|
||||
this.buildQueryForList(filters, config),
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<Currency>(filters, config)
|
||||
|
||||
if (filters.code) {
|
||||
queryOptions.where["code"] = { $in: filters.code }
|
||||
}
|
||||
|
||||
return queryOptions
|
||||
}
|
||||
|
||||
@InjectTransactionManager("currencyRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreateCurrencyDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.currencyRepository_ as CurrencyRepository).create(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("currencyRepository_")
|
||||
async update(
|
||||
data: ServiceTypes.UpdateCurrencyDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.currencyRepository_ as CurrencyRepository).update(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("currencyRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.currencyRepository_.delete(ids, sharedContext)
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { MoneyAmount } from "@models"
|
||||
import { MoneyAmountRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -16,105 +9,19 @@ type InjectedDependencies = {
|
||||
|
||||
export default class MoneyAmountService<
|
||||
TEntity extends MoneyAmount = MoneyAmount
|
||||
> {
|
||||
protected readonly moneyAmountRepository_: DAL.RepositoryService
|
||||
|
||||
constructor({ moneyAmountRepository }: InjectedDependencies) {
|
||||
this.moneyAmountRepository_ = moneyAmountRepository
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreateMoneyAmountDTO
|
||||
update: ServiceTypes.UpdateMoneyAmountDTO
|
||||
},
|
||||
{
|
||||
list: ServiceTypes.FilterableMoneyAmountProps
|
||||
listAndCount: ServiceTypes.FilterableMoneyAmountProps
|
||||
}
|
||||
|
||||
@InjectManager("moneyAmountRepository_")
|
||||
async retrieve(
|
||||
moneyAmountId: string,
|
||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<MoneyAmount, ServiceTypes.MoneyAmountDTO>({
|
||||
id: moneyAmountId,
|
||||
entityName: MoneyAmount.name,
|
||||
repository: this.moneyAmountRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("moneyAmountRepository_")
|
||||
async list(
|
||||
filters: ServiceTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<MoneyAmount>(
|
||||
filters,
|
||||
config
|
||||
)
|
||||
|
||||
return (await this.moneyAmountRepository_.find(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectManager("moneyAmountRepository_")
|
||||
async listAndCount(
|
||||
filters: ServiceTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<MoneyAmount>(
|
||||
filters,
|
||||
config
|
||||
)
|
||||
|
||||
return (await this.moneyAmountRepository_.findAndCount(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("moneyAmountRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreateMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.moneyAmountRepository_ as MoneyAmountRepository).create(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("moneyAmountRepository_")
|
||||
async update(
|
||||
data: ServiceTypes.UpdateMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.moneyAmountRepository_ as MoneyAmountRepository).update(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("moneyAmountRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.moneyAmountRepository_.delete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("moneyAmountRepository_")
|
||||
async softDelete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.moneyAmountRepository_.softDelete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("moneyAmountRepository_")
|
||||
async restore(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], Record<string, unknown[]>]> {
|
||||
return await this.moneyAmountRepository_.restore(ids, sharedContext)
|
||||
>(MoneyAmount)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceListRuleValue } from "@models"
|
||||
import { PriceListRuleValueRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -18,99 +9,19 @@ type InjectedDependencies = {
|
||||
|
||||
export default class PriceListRuleValueService<
|
||||
TEntity extends PriceListRuleValue = PriceListRuleValue
|
||||
> {
|
||||
protected readonly priceListRuleValueRepository_: DAL.RepositoryService
|
||||
|
||||
constructor({ priceListRuleValueRepository }: InjectedDependencies) {
|
||||
this.priceListRuleValueRepository_ = priceListRuleValueRepository
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreatePriceListRuleValueDTO
|
||||
update: ServiceTypes.UpdatePriceListRuleValueDTO
|
||||
},
|
||||
{
|
||||
list: ServiceTypes.FilterablePriceListRuleValueProps
|
||||
listAndCount: ServiceTypes.FilterablePriceListRuleValueProps
|
||||
}
|
||||
|
||||
@InjectManager("priceListRuleValueRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceListRuleValue,
|
||||
ServiceTypes.PriceListRuleValueDTO
|
||||
>({
|
||||
id: priceSetId,
|
||||
entityName: PriceListRuleValue.name,
|
||||
repository: this.priceListRuleValueRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("priceListRuleValueRepository_")
|
||||
async list(
|
||||
filters: ServiceTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRuleValue>(
|
||||
filters,
|
||||
config
|
||||
)
|
||||
|
||||
return (await this.priceListRuleValueRepository_.find(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectManager("priceListRuleValueRepository_")
|
||||
async listAndCount(
|
||||
filters: ServiceTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRuleValue>(
|
||||
filters,
|
||||
config
|
||||
)
|
||||
|
||||
return (await this.priceListRuleValueRepository_.findAndCount(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(
|
||||
shouldForceTransaction,
|
||||
"priceListRuleValueRepository_"
|
||||
)
|
||||
async create(
|
||||
data: ServiceTypes.CreatePriceListRuleValueDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
this.priceListRuleValueRepository_ as PriceListRuleValueRepository
|
||||
).create(data, sharedContext)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(
|
||||
shouldForceTransaction,
|
||||
"priceListRuleValueRepository_"
|
||||
)
|
||||
async update(
|
||||
data: ServiceTypes.UpdatePriceListRuleValueDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
this.priceListRuleValueRepository_ as PriceListRuleValueRepository
|
||||
).update(data, sharedContext)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(
|
||||
doNotForceTransaction,
|
||||
"priceListRuleValueRepository_"
|
||||
)
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceListRuleValueRepository_.delete(ids, sharedContext)
|
||||
>(PriceListRuleValue)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceListRule } from "@models"
|
||||
import { PriceListRuleRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -18,87 +9,19 @@ type InjectedDependencies = {
|
||||
|
||||
export default class PriceListRuleService<
|
||||
TEntity extends PriceListRule = PriceListRule
|
||||
> {
|
||||
protected readonly priceListRuleRepository_: DAL.RepositoryService
|
||||
|
||||
constructor({ priceListRuleRepository }: InjectedDependencies) {
|
||||
this.priceListRuleRepository_ = priceListRuleRepository
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreatePriceListRuleDTO
|
||||
update: ServiceTypes.UpdatePriceListRuleDTO
|
||||
},
|
||||
{
|
||||
list: ServiceTypes.FilterablePriceListRuleProps
|
||||
listAndCount: ServiceTypes.FilterablePriceListRuleProps
|
||||
}
|
||||
|
||||
@InjectManager("priceListRuleRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceListRule, ServiceTypes.PriceListRuleDTO>({
|
||||
id: priceSetId,
|
||||
entityName: PriceListRule.name,
|
||||
repository: this.priceListRuleRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("priceListRuleRepository_")
|
||||
async list(
|
||||
filters: ServiceTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRule>(
|
||||
filters,
|
||||
config
|
||||
)
|
||||
|
||||
return (await this.priceListRuleRepository_.find(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectManager("priceListRuleRepository_")
|
||||
async listAndCount(
|
||||
filters: ServiceTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRule>(
|
||||
filters,
|
||||
config
|
||||
)
|
||||
|
||||
return (await this.priceListRuleRepository_.findAndCount(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRuleRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreatePriceListRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
this.priceListRuleRepository_ as PriceListRuleRepository
|
||||
).create(data, sharedContext)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRuleRepository_")
|
||||
async update(
|
||||
data: ServiceTypes.UpdatePriceListRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
this.priceListRuleRepository_ as PriceListRuleRepository
|
||||
).update(data, sharedContext)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(doNotForceTransaction, "priceListRuleRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceListRuleRepository_.delete(ids, sharedContext)
|
||||
>(PriceListRule)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,98 +1,27 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceList } from "@models"
|
||||
import { PriceListRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceListRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
protected readonly priceListRepository_: DAL.RepositoryService
|
||||
|
||||
constructor({ priceListRepository }: InjectedDependencies) {
|
||||
this.priceListRepository_ = priceListRepository
|
||||
export default class PriceListService<
|
||||
TEntity extends PriceList = PriceList
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreatePriceListDTO
|
||||
update: ServiceTypes.UpdatePriceListDTO
|
||||
},
|
||||
{
|
||||
list: ServiceTypes.FilterablePriceListProps
|
||||
listAndCount: ServiceTypes.FilterablePriceListProps
|
||||
}
|
||||
|
||||
@InjectManager("priceListRepository_")
|
||||
async retrieve(
|
||||
priceListId: string,
|
||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceList, ServiceTypes.PriceListDTO>({
|
||||
id: priceListId,
|
||||
entityName: PriceList.name,
|
||||
repository: this.priceListRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("priceListRepository_")
|
||||
async list(
|
||||
filters: ServiceTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceList>(filters, config)
|
||||
|
||||
return (await this.priceListRepository_.find(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectManager("priceListRepository_")
|
||||
async listAndCount(
|
||||
filters: ServiceTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceList>(filters, config)
|
||||
|
||||
return (await this.priceListRepository_.findAndCount(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreatePriceListDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceListRepository_ as PriceListRepository).create(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRepository_")
|
||||
async update(
|
||||
data: Omit<ServiceTypes.UpdatePriceListDTO, "rules">[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceListRepository_ as PriceListRepository).update(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(doNotForceTransaction, "priceListRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceListRepository_.delete(ids, sharedContext)
|
||||
>(PriceList)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceRule } from "@models"
|
||||
import { PriceRuleRepository } from "@repositories"
|
||||
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
@@ -15,83 +8,21 @@ type InjectedDependencies = {
|
||||
priceRuleRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
protected readonly priceRuleRepository_: DAL.RepositoryService
|
||||
|
||||
constructor({ priceRuleRepository }: InjectedDependencies) {
|
||||
this.priceRuleRepository_ = priceRuleRepository
|
||||
export default class PriceRuleService<
|
||||
TEntity extends PriceRule = PriceRule
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreatePriceRuleDTO
|
||||
update: ServiceTypes.UpdatePriceRuleDTO
|
||||
},
|
||||
{
|
||||
list: ServiceTypes.FilterablePriceRuleProps
|
||||
listAndCount: ServiceTypes.FilterablePriceRuleProps
|
||||
}
|
||||
|
||||
@InjectManager("priceRuleRepository_")
|
||||
async retrieve(
|
||||
priceRuleId: string,
|
||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceRule, ServiceTypes.PriceRuleDTO>({
|
||||
id: priceRuleId,
|
||||
entityName: PriceRule.name,
|
||||
repository: this.priceRuleRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("priceRuleRepository_")
|
||||
async list(
|
||||
filters: ServiceTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryConfig = ModulesSdkUtils.buildQuery<PriceRule>(filters, config)
|
||||
|
||||
return (await this.priceRuleRepository_.find(
|
||||
queryConfig,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectManager("priceRuleRepository_")
|
||||
async listAndCount(
|
||||
filters: ServiceTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryConfig = ModulesSdkUtils.buildQuery<PriceRule>(filters, config)
|
||||
|
||||
return (await this.priceRuleRepository_.findAndCount(
|
||||
queryConfig,
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceRuleRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreatePriceRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceRuleRepository_ as PriceRuleRepository).create(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceRuleRepository_")
|
||||
async update(
|
||||
data: ServiceTypes.UpdatePriceRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceRuleRepository_ as PriceRuleRepository).update(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceRuleRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceRuleRepository_.delete(ids, sharedContext)
|
||||
>(PriceRule)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceSetMoneyAmountRules } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
@@ -15,96 +9,15 @@ type InjectedDependencies = {
|
||||
|
||||
export default class PriceSetMoneyAmountRulesService<
|
||||
TEntity extends PriceSetMoneyAmountRules = PriceSetMoneyAmountRules
|
||||
> {
|
||||
protected readonly priceSetMoneyAmountRulesRepository_: DAL.RepositoryService
|
||||
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreatePriceSetMoneyAmountRulesDTO
|
||||
update: ServiceTypes.UpdatePriceSetMoneyAmountRulesDTO
|
||||
}
|
||||
>(PriceSetMoneyAmountRules)<TEntity> {
|
||||
constructor({ priceSetMoneyAmountRulesRepository }: InjectedDependencies) {
|
||||
this.priceSetMoneyAmountRulesRepository_ =
|
||||
priceSetMoneyAmountRulesRepository
|
||||
}
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
||||
async retrieve(
|
||||
priceSetMoneyAmountRulesId: string,
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceSetMoneyAmountRules,
|
||||
ServiceTypes.PriceSetMoneyAmountRulesDTO
|
||||
>({
|
||||
id: priceSetMoneyAmountRulesId,
|
||||
identifierColumn: "id",
|
||||
entityName: PriceSetMoneyAmountRules.name,
|
||||
repository: this.priceSetMoneyAmountRulesRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
||||
async list(
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.find(
|
||||
this.buildQueryForList(filters, config),
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
||||
async listAndCount(
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.findAndCount(
|
||||
this.buildQueryForList(filters, config),
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSetMoneyAmountRules>(
|
||||
filters,
|
||||
config
|
||||
)
|
||||
|
||||
return queryOptions
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreatePriceSetMoneyAmountRulesDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.create(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
||||
async update(
|
||||
data: ServiceTypes.UpdatePriceSetMoneyAmountRulesDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.update(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceSetMoneyAmountRulesRepository_.delete(ids, sharedContext)
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceSet, PriceSetMoneyAmount } from "@models"
|
||||
import { PriceSetMoneyAmountRepository } from "@repositories"
|
||||
import { InjectManager, MedusaContext, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceSetMoneyAmount } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -16,95 +9,51 @@ type InjectedDependencies = {
|
||||
|
||||
export default class PriceSetMoneyAmountService<
|
||||
TEntity extends PriceSetMoneyAmount = PriceSetMoneyAmount
|
||||
> {
|
||||
protected readonly priceSetMoneyAmountRepository_: DAL.RepositoryService
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreatePriceSetMoneyAmountDTO
|
||||
update: ServiceTypes.UpdatePriceSetMoneyAmountDTO
|
||||
}
|
||||
>(PriceSetMoneyAmount)<TEntity> {
|
||||
protected readonly priceSetMoneyAmountRepository_: DAL.RepositoryService<TEntity>
|
||||
|
||||
constructor({ priceSetMoneyAmountRepository }: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
this.priceSetMoneyAmountRepository_ = priceSetMoneyAmountRepository
|
||||
}
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceSetMoneyAmount,
|
||||
ServiceTypes.PriceSetMoneyAmountDTO
|
||||
>({
|
||||
id: priceSetId,
|
||||
entityName: PriceSet.name,
|
||||
repository: this.priceSetMoneyAmountRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRepository_")
|
||||
async list(
|
||||
async list<TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO>(
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {},
|
||||
config: FindConfig<TEntityMethod> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRepository_.find(
|
||||
return await this.priceSetMoneyAmountRepository_.find(
|
||||
this.buildQueryForList(filters, config),
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
)
|
||||
}
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRepository_")
|
||||
async listAndCount(
|
||||
async listAndCount<TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO>(
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {},
|
||||
config: FindConfig<TEntityMethod> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.priceSetMoneyAmountRepository_.findAndCount(
|
||||
return await this.priceSetMoneyAmountRepository_.findAndCount(
|
||||
this.buildQueryForList(filters, config),
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
)
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
private buildQueryForList<
|
||||
TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO
|
||||
>(
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {}
|
||||
config: FindConfig<TEntityMethod> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
|
||||
if (filters.id) {
|
||||
queryOptions.where.id = { $in: filters.id }
|
||||
}
|
||||
|
||||
return queryOptions
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
this
|
||||
.priceSetMoneyAmountRepository_ as unknown as PriceSetMoneyAmountRepository
|
||||
).create(data, sharedContext)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
||||
async update(
|
||||
data: ServiceTypes.UpdatePriceSetMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
this
|
||||
.priceSetMoneyAmountRepository_ as unknown as PriceSetMoneyAmountRepository
|
||||
).update(data, sharedContext)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceSetMoneyAmountRepository_.delete(ids, sharedContext)
|
||||
return ModulesSdkUtils.buildQuery<TEntity>(filters, config)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceSet, PriceSetRuleType } from "@models"
|
||||
import { PriceSetRuleTypeRepository } from "src/repositories/price-set-rule-type"
|
||||
import { InjectManager, MedusaContext, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceSetRuleType } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -16,93 +9,51 @@ type InjectedDependencies = {
|
||||
|
||||
export default class PriceSetRuleTypeService<
|
||||
TEntity extends PriceSetRuleType = PriceSetRuleType
|
||||
> {
|
||||
protected readonly priceSetRuleTypeRepository_: DAL.RepositoryService
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreatePriceSetRuleTypeDTO
|
||||
update: ServiceTypes.UpdatePriceSetRuleTypeDTO
|
||||
}
|
||||
>(PriceSetRuleType)<TEntity> {
|
||||
protected readonly priceSetRuleTypeRepository_: DAL.RepositoryService<TEntity>
|
||||
|
||||
constructor({ priceSetRuleTypeRepository }: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
this.priceSetRuleTypeRepository_ = priceSetRuleTypeRepository
|
||||
}
|
||||
|
||||
@InjectManager("priceSetRuleTypeRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<ServiceTypes.PriceSetRuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceSetRuleType,
|
||||
ServiceTypes.PriceSetRuleTypeDTO
|
||||
>({
|
||||
id: priceSetId,
|
||||
entityName: PriceSet.name,
|
||||
repository: this.priceSetRuleTypeRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("priceSetRuleTypeRepository_")
|
||||
async list(
|
||||
async list<TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO>(
|
||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
config: FindConfig<TEntityMethod> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetRuleTypeRepository_.find(
|
||||
return await this.priceSetRuleTypeRepository_.find(
|
||||
this.buildQueryForList(filters, config),
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
)
|
||||
}
|
||||
|
||||
@InjectManager("priceSetRuleTypeRepository_")
|
||||
async listAndCount(
|
||||
async listAndCount<TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO>(
|
||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
config: FindConfig<TEntityMethod> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.priceSetRuleTypeRepository_.findAndCount(
|
||||
return await this.priceSetRuleTypeRepository_.findAndCount(
|
||||
this.buildQueryForList(filters, config),
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
)
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
private buildQueryForList<
|
||||
TEntityMethod = ServiceTypes.PriceSetMoneyAmountDTO
|
||||
>(
|
||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {}
|
||||
config: FindConfig<TEntityMethod> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
|
||||
if (filters.id) {
|
||||
queryOptions.where.id = { $in: filters.id }
|
||||
}
|
||||
|
||||
return queryOptions
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreatePriceSetRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
this.priceSetRuleTypeRepository_ as PriceSetRuleTypeRepository
|
||||
).create(data, sharedContext)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
||||
async update(
|
||||
data: ServiceTypes.UpdatePriceSetRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
this.priceSetRuleTypeRepository_ as PriceSetRuleTypeRepository
|
||||
).update(data, sharedContext)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceSetRuleTypeRepository_.delete(ids, sharedContext)
|
||||
return ModulesSdkUtils.buildQuery<TEntity>(filters, config)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceSet } from "@models"
|
||||
import { PriceSetRepository } from "@repositories"
|
||||
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
@@ -15,83 +8,21 @@ type InjectedDependencies = {
|
||||
priceSetRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
protected readonly priceSetRepository_: DAL.RepositoryService
|
||||
|
||||
constructor({ priceSetRepository }: InjectedDependencies) {
|
||||
this.priceSetRepository_ = priceSetRepository
|
||||
export default class PriceSetService<
|
||||
TEntity extends PriceSet = PriceSet
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: Omit<ServiceTypes.CreatePriceSetDTO, "rules">
|
||||
update: Omit<ServiceTypes.UpdatePriceSetDTO, "rules">
|
||||
},
|
||||
{
|
||||
list: ServiceTypes.FilterablePriceSetProps
|
||||
listAndCount: ServiceTypes.FilterablePriceSetProps
|
||||
}
|
||||
|
||||
@InjectManager("priceSetRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceSet, ServiceTypes.PriceSetDTO>({
|
||||
id: priceSetId,
|
||||
entityName: PriceSet.name,
|
||||
repository: this.priceSetRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("priceSetRepository_")
|
||||
async list(
|
||||
filters: ServiceTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
|
||||
return (await this.priceSetRepository_.find(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectManager("priceSetRepository_")
|
||||
async listAndCount(
|
||||
filters: ServiceTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
|
||||
return (await this.priceSetRepository_.findAndCount(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetRepository_")
|
||||
async create(
|
||||
data: Omit<ServiceTypes.CreatePriceSetDTO, "rules">[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceSetRepository_ as PriceSetRepository).create(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetRepository_")
|
||||
async update(
|
||||
data: Omit<ServiceTypes.UpdatePriceSetDTO, "rules">[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceSetRepository_ as PriceSetRepository).update(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("priceSetRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.priceSetRepository_.delete(ids, sharedContext)
|
||||
>(PriceSet)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
retrieveEntity,
|
||||
validateRuleAttributes,
|
||||
} from "@medusajs/utils"
|
||||
import { RuleType } from "@models"
|
||||
@@ -14,67 +12,34 @@ type InjectedDependencies = {
|
||||
ruleTypeRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
protected readonly ruleTypeRepository_: DAL.RepositoryService
|
||||
export default class RuleTypeService<
|
||||
TEntity extends RuleType = RuleType
|
||||
> extends ModulesSdkUtils.abstractServiceFactory<
|
||||
InjectedDependencies,
|
||||
{
|
||||
create: ServiceTypes.CreateRuleTypeDTO
|
||||
update: ServiceTypes.UpdateRuleTypeDTO
|
||||
},
|
||||
{
|
||||
list: ServiceTypes.FilterableRuleTypeProps
|
||||
listAndCount: ServiceTypes.FilterableRuleTypeProps
|
||||
}
|
||||
>(RuleType)<TEntity> {
|
||||
protected readonly ruleTypeRepository_: DAL.RepositoryService<TEntity>
|
||||
|
||||
constructor({ ruleTypeRepository }: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
this.ruleTypeRepository_ = ruleTypeRepository
|
||||
}
|
||||
|
||||
@InjectManager("ruleTypeRepository_")
|
||||
async retrieve(
|
||||
ruleTypeId: string,
|
||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<RuleType, ServiceTypes.RuleTypeDTO>({
|
||||
id: ruleTypeId,
|
||||
identifierColumn: "id",
|
||||
entityName: RuleType.name,
|
||||
repository: this.ruleTypeRepository_,
|
||||
config,
|
||||
sharedContext,
|
||||
})) as TEntity
|
||||
}
|
||||
|
||||
@InjectManager("ruleTypeRepository_")
|
||||
async list(
|
||||
filters: ServiceTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<RuleType>(filters, config)
|
||||
|
||||
return (await this.ruleTypeRepository_.find(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectManager("ruleTypeRepository_")
|
||||
async listAndCount(
|
||||
filters: ServiceTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<RuleType>(filters, config)
|
||||
|
||||
return (await this.ruleTypeRepository_.findAndCount(
|
||||
queryOptions,
|
||||
sharedContext
|
||||
)) as [TEntity[], number]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
async create(
|
||||
data: ServiceTypes.CreateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
validateRuleAttributes(data.map((d) => d.rule_attribute))
|
||||
return (await this.ruleTypeRepository_.create(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
return await this.ruleTypeRepository_.create(data, sharedContext)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
@@ -83,17 +48,6 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
validateRuleAttributes(data.map((d) => d.rule_attribute))
|
||||
return (await this.ruleTypeRepository_.update(
|
||||
data,
|
||||
sharedContext
|
||||
)) as TEntity[]
|
||||
}
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
async delete(
|
||||
ids: string[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
await this.ruleTypeRepository_.delete(ids, sharedContext)
|
||||
return await this.ruleTypeRepository_.update(data, sharedContext)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user