Files
medusa-store/packages/fulfillment/src/services/fulfillment-module-service.ts
Adrien de Peretti 12054f5c01 feat: Fulfillment module basic structure (#6319)
**What**
Scafold the fulfillment module basic structure

**Bonus**
Simplified module scaffolding with new factories and less directories to manage
- mikro orm connection loader factory
- initialize factory

FIXES CORE-1709
FIXES CORE-1710
2024-02-06 13:29:36 +00:00

92 lines
2.5 KiB
TypeScript

import {
Context,
DAL,
FulfillmentTypes,
IFulfillmentModuleService,
InternalModuleDeclaration,
ModuleJoinerConfig,
ModulesSdkTypes,
} from "@medusajs/types"
import { InjectTransactionManager, ModulesSdkUtils } from "@medusajs/utils"
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
import { FulfillmentSet } from "@models"
type InjectedDependencies = {
baseRepository: DAL.RepositoryService
fulfillmentService: ModulesSdkTypes.InternalModuleService<any>
}
export default class FulfillmentModuleService<
TEntity extends FulfillmentSet = FulfillmentSet
>
extends ModulesSdkUtils.abstractModuleServiceFactory<
InjectedDependencies,
any, // TODO Create appropriate DTO
{}
>(FulfillmentSet, [], entityNameToLinkableKeysMap)
implements IFulfillmentModuleService
{
protected baseRepository_: DAL.RepositoryService
protected readonly fulfillmentService_: ModulesSdkTypes.InternalModuleService<TEntity>
constructor(
{ baseRepository, fulfillmentService }: InjectedDependencies,
protected readonly moduleDeclaration: InternalModuleDeclaration
) {
// @ts-ignore
super(...arguments)
this.baseRepository_ = baseRepository
this.fulfillmentService_ = fulfillmentService
}
__joinerConfig(): ModuleJoinerConfig {
return joinerConfig
}
create(
data: any[],
sharedContext?: Context
): Promise<FulfillmentTypes.FulfillmentDTO[]>
create(
data: any,
sharedContext?: Context
): Promise<FulfillmentTypes.FulfillmentDTO>
// TODO Implement the methods from the interface and change type
@InjectTransactionManager("baseRepository_")
async create(
data: any[] | any,
sharedContext?: Context
): Promise<
FulfillmentTypes.FulfillmentDTO | FulfillmentTypes.FulfillmentDTO[]
> {
return await Promise.resolve(
[] as FulfillmentTypes.FulfillmentDTO[] | FulfillmentTypes.FulfillmentDTO
)
}
// TODO Implement the methods from the interface and change type
update(
data: any[],
sharedContext?: Context
): Promise<FulfillmentTypes.FulfillmentDTO[]>
update(
data: any,
sharedContext?: Context
): Promise<FulfillmentTypes.FulfillmentDTO>
@InjectTransactionManager("baseRepository_")
async update(
data: any,
sharedContext?: Context
): Promise<
FulfillmentTypes.FulfillmentDTO | FulfillmentTypes.FulfillmentDTO[]
> {
return await Promise.resolve(
[] as FulfillmentTypes.FulfillmentDTO[] | FulfillmentTypes.FulfillmentDTO
)
}
}