chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
committed by
GitHub
parent
7a351eef09
commit
4eae25e1ef
@@ -0,0 +1 @@
|
||||
it("noop", () => {})
|
||||
3
packages/modules/pricing/src/services/index.ts
Normal file
3
packages/modules/pricing/src/services/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { default as PriceListService } from "./price-list"
|
||||
export { default as PricingModuleService } from "./pricing-module"
|
||||
export { default as RuleTypeService } from "./rule-type"
|
||||
69
packages/modules/pricing/src/services/price-list.ts
Normal file
69
packages/modules/pricing/src/services/price-list.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { GetIsoStringFromDate, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { PriceList } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceListRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class PriceListService<
|
||||
TEntity extends PriceList = PriceList
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
PriceList
|
||||
)<TEntity> {
|
||||
constructor(container: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
}
|
||||
|
||||
create(
|
||||
data: ServiceTypes.CreatePriceListDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<TEntity[]>
|
||||
create(
|
||||
data: ServiceTypes.CreatePriceListDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<TEntity>
|
||||
|
||||
async create(
|
||||
data: ServiceTypes.CreatePriceListDTO | ServiceTypes.CreatePriceListDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
const priceLists = this.normalizePriceListDate(data_)
|
||||
return await super.create(priceLists, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
update(data: any[], sharedContext?: Context): Promise<TEntity[]>
|
||||
// @ts-ignore
|
||||
update(data: any, sharedContext?: Context): Promise<TEntity>
|
||||
|
||||
// TODO: Add support for selector? and then rm ts ignore
|
||||
// @ts-ignore
|
||||
async update(
|
||||
data: ServiceTypes.UpdatePriceListDTO | ServiceTypes.UpdatePriceListDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
const priceLists = this.normalizePriceListDate(data_)
|
||||
return await super.update(priceLists, sharedContext)
|
||||
}
|
||||
|
||||
protected normalizePriceListDate(
|
||||
data: (ServiceTypes.UpdatePriceListDTO | ServiceTypes.CreatePriceListDTO)[]
|
||||
) {
|
||||
return data.map((priceListData: any) => {
|
||||
if (!!priceListData.starts_at) {
|
||||
priceListData.starts_at = GetIsoStringFromDate(priceListData.starts_at)
|
||||
}
|
||||
|
||||
if (!!priceListData.ends_at) {
|
||||
priceListData.ends_at = GetIsoStringFromDate(priceListData.ends_at)
|
||||
}
|
||||
|
||||
return priceListData
|
||||
})
|
||||
}
|
||||
}
|
||||
1669
packages/modules/pricing/src/services/pricing-module.ts
Normal file
1669
packages/modules/pricing/src/services/pricing-module.ts
Normal file
File diff suppressed because it is too large
Load Diff
68
packages/modules/pricing/src/services/rule-type.ts
Normal file
68
packages/modules/pricing/src/services/rule-type.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { Context, DAL, PricingTypes } from "@medusajs/types"
|
||||
import {
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
validateRuleAttributes,
|
||||
} from "@medusajs/utils"
|
||||
import { RuleType } from "@models"
|
||||
|
||||
type InjectedDependencies = {
|
||||
ruleTypeRepository: DAL.RepositoryService
|
||||
}
|
||||
|
||||
export default class RuleTypeService<
|
||||
TEntity extends RuleType = RuleType
|
||||
> extends ModulesSdkUtils.internalModuleServiceFactory<InjectedDependencies>(
|
||||
RuleType
|
||||
)<TEntity> {
|
||||
protected readonly ruleTypeRepository_: DAL.RepositoryService<TEntity>
|
||||
|
||||
constructor({ ruleTypeRepository }: InjectedDependencies) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
this.ruleTypeRepository_ = ruleTypeRepository
|
||||
}
|
||||
|
||||
create(
|
||||
data: PricingTypes.CreateRuleTypeDTO,
|
||||
sharedContext: Context
|
||||
): Promise<TEntity>
|
||||
create(
|
||||
data: PricingTypes.CreateRuleTypeDTO[],
|
||||
sharedContext: Context
|
||||
): Promise<TEntity[]>
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreateRuleTypeDTO | PricingTypes.CreateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
validateRuleAttributes(data_.map((d) => d.rule_attribute))
|
||||
return await super.create(data, sharedContext)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
update(
|
||||
data: PricingTypes.UpdateRuleTypeDTO[],
|
||||
sharedContext: Context
|
||||
): Promise<TEntity[]>
|
||||
// @ts-ignore
|
||||
update(
|
||||
data: PricingTypes.UpdateRuleTypeDTO,
|
||||
sharedContext: Context
|
||||
): Promise<TEntity>
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
// TODO: add support for selector? and then rm ts ignore
|
||||
// @ts-ignore
|
||||
async update(
|
||||
data: PricingTypes.UpdateRuleTypeDTO | PricingTypes.UpdateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity | TEntity[]> {
|
||||
const data_ = Array.isArray(data) ? data : [data]
|
||||
validateRuleAttributes(data_.map((d) => d.rule_attribute))
|
||||
return await super.update(data, sharedContext)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user