feat(medusa): Simplify the transaction base service (#2007)

**What**
Simplify the transaction base service.

**How**

In fact, it does not need to be template and reduce the extensibility as the type is internally enforce. Now, the type is deduced by this which can be any derived class.
This commit is contained in:
Adrien de Peretti
2022-08-12 09:17:39 +00:00
committed by GitHub
parent cbe2b7f687
commit 79acc38a57
46 changed files with 82 additions and 115 deletions
@@ -31,7 +31,7 @@ import { IsString } from "class-validator"
* description: The Download URL of the file * description: The Download URL of the file
*/ */
export default async (req, res) => { export default async (req, res) => {
const fileService: AbstractFileService<any> = req.scope.resolve("fileService") const fileService: AbstractFileService = req.scope.resolve("fileService")
const url = await fileService.getPresignedDownloadUrl({ const url = await fileService.getPresignedDownloadUrl({
fileKey: (req.validatedBody as AdminPostUploadsDownloadUrlReq).file_key, fileKey: (req.validatedBody as AdminPostUploadsDownloadUrlReq).file_key,
@@ -4,7 +4,7 @@ import { TransactionBaseService } from "../transaction-base-service"
describe("TransactionBaseService", () => { describe("TransactionBaseService", () => {
it("should cloned the child class withTransaction", () => { it("should cloned the child class withTransaction", () => {
class Child extends TransactionBaseService<Child> { class Child extends TransactionBaseService {
protected manager_!: EntityManager protected manager_!: EntityManager
protected transactionManager_!: EntityManager protected transactionManager_!: EntityManager
@@ -4,8 +4,7 @@ import { ProductExportBatchJob } from "../strategies/batch-jobs/product"
import { BatchJobService } from "../services" import { BatchJobService } from "../services"
import { BatchJob } from "../models" import { BatchJob } from "../models"
export interface IBatchJobStrategy<T extends TransactionBaseService<never>> export interface IBatchJobStrategy extends TransactionBaseService {
extends TransactionBaseService<T> {
/** /**
* Method for preparing a batch job for processing * Method for preparing a batch job for processing
*/ */
@@ -30,12 +29,9 @@ export interface IBatchJobStrategy<T extends TransactionBaseService<never>>
buildTemplate(): Promise<string> buildTemplate(): Promise<string>
} }
export abstract class AbstractBatchJobStrategy< export abstract class AbstractBatchJobStrategy
T extends TransactionBaseService<never, TContainer>, extends TransactionBaseService
TContainer = unknown implements IBatchJobStrategy
>
extends TransactionBaseService<T, TContainer>
implements IBatchJobStrategy<T>
{ {
static identifier: string static identifier: string
static batchType: string static batchType: string
@@ -113,6 +109,6 @@ export abstract class AbstractBatchJobStrategy<
export function isBatchJobStrategy( export function isBatchJobStrategy(
object: unknown object: unknown
): object is IBatchJobStrategy<never> { ): object is IBatchJobStrategy {
return object instanceof AbstractBatchJobStrategy return object instanceof AbstractBatchJobStrategy
} }
@@ -30,8 +30,7 @@ export type UploadStreamDescriptorType = {
[x: string]: unknown [x: string]: unknown
} }
export interface IFileService<T extends TransactionBaseService<any>> export interface IFileService extends TransactionBaseService {
extends TransactionBaseService<T> {
/** /**
* upload file to fileservice * upload file to fileservice
* @param file Multer file from express multipart/form-data * @param file Multer file from express multipart/form-data
@@ -69,9 +68,9 @@ export interface IFileService<T extends TransactionBaseService<any>>
* */ * */
getPresignedDownloadUrl(fileData: GetUploadedFileType): Promise<string> getPresignedDownloadUrl(fileData: GetUploadedFileType): Promise<string>
} }
export abstract class AbstractFileService<T extends TransactionBaseService<any>> export abstract class AbstractFileService
extends TransactionBaseService<T> extends TransactionBaseService
implements IFileService<T> implements IFileService
{ {
abstract upload( abstract upload(
fileData: Express.Multer.File fileData: Express.Multer.File
@@ -7,8 +7,7 @@ type ReturnedData = {
data: Record<string, unknown> data: Record<string, unknown>
} }
export interface INotificationService<T extends TransactionBaseService<never>> export interface INotificationService extends TransactionBaseService {
extends TransactionBaseService<T> {
sendNotification( sendNotification(
event: string, event: string,
data: unknown, data: unknown,
@@ -22,11 +21,9 @@ export interface INotificationService<T extends TransactionBaseService<never>>
): Promise<ReturnedData> ): Promise<ReturnedData>
} }
export abstract class AbstractNotificationService< export abstract class AbstractNotificationService
T extends TransactionBaseService<never> extends TransactionBaseService
> implements INotificationService
extends TransactionBaseService<T>
implements INotificationService<T>
{ {
static identifier: string static identifier: string
@@ -12,8 +12,8 @@ export type Data = Record<string, unknown>
export type PaymentData = Data export type PaymentData = Data
export type PaymentSessionData = Data export type PaymentSessionData = Data
export interface PaymentService<T extends TransactionBaseService<never>> export interface PaymentService<T extends TransactionBaseService>
extends TransactionBaseService<T> { extends TransactionBaseService {
getIdentifier(): string getIdentifier(): string
getPaymentData(paymentSession: PaymentSession): Promise<PaymentData> getPaymentData(paymentSession: PaymentSession): Promise<PaymentData>
@@ -50,10 +50,8 @@ export interface PaymentService<T extends TransactionBaseService<never>>
getStatus(data: Data): Promise<PaymentSessionStatus> getStatus(data: Data): Promise<PaymentSessionStatus>
} }
export abstract class AbstractPaymentService< export abstract class AbstractPaymentService<T extends TransactionBaseService>
T extends TransactionBaseService<never> extends TransactionBaseService
>
extends TransactionBaseService<T>
implements PaymentService<T> implements PaymentService<T>
{ {
protected constructor(container: unknown, config?: Record<string, unknown>) { protected constructor(container: unknown, config?: Record<string, unknown>) {
@@ -1,7 +1,7 @@
import { TransactionBaseService } from "./transaction-base-service" import { TransactionBaseService } from "./transaction-base-service"
import { SearchService } from "medusa-interfaces" import { SearchService } from "medusa-interfaces"
export interface ISearchService<T extends TransactionBaseService<never>> { export interface ISearchService {
options: Record<string, unknown> options: Record<string, unknown>
/** /**
@@ -72,11 +72,9 @@ export interface ISearchService<T extends TransactionBaseService<never>> {
updateSettings(indexName: string, settings: unknown): unknown updateSettings(indexName: string, settings: unknown): unknown
} }
export abstract class AbstractSearchService< export abstract class AbstractSearchService
T extends TransactionBaseService<never> extends TransactionBaseService
> implements ISearchService
extends TransactionBaseService<T>
implements ISearchService<T>
{ {
abstract readonly isDefault abstract readonly isDefault
protected readonly options_: Record<string, unknown> protected readonly options_: Record<string, unknown>
@@ -1,34 +1,31 @@
import { EntityManager } from "typeorm" import { EntityManager } from "typeorm"
import { IsolationLevel } from "typeorm/driver/types/IsolationLevel" import { IsolationLevel } from "typeorm/driver/types/IsolationLevel"
export abstract class TransactionBaseService< export abstract class TransactionBaseService {
TChild extends TransactionBaseService<TChild, TContainer>,
TContainer = unknown
> {
protected abstract manager_: EntityManager protected abstract manager_: EntityManager
protected abstract transactionManager_: EntityManager | undefined protected abstract transactionManager_: EntityManager | undefined
protected constructor( protected constructor(
protected readonly container: TContainer, protected readonly __container__: any,
protected readonly configModule?: Record<string, unknown> protected readonly __configModule__?: Record<string, unknown>
) {} ) {}
withTransaction(transactionManager?: EntityManager): this | TChild { withTransaction(transactionManager?: EntityManager): this {
if (!transactionManager) { if (!transactionManager) {
return this return this
} }
const cloned = new (<any>this.constructor)( const cloned = new (<any>this.constructor)(
{ {
...this.container, ...this.__container__,
manager: transactionManager, manager: transactionManager,
}, },
this.configModule this.__configModule__
) )
cloned.transactionManager_ = transactionManager cloned.transactionManager_ = transactionManager
return cloned as TChild return cloned
} }
protected shouldRetryTransaction_( protected shouldRetryTransaction_(
+1 -1
View File
@@ -22,7 +22,7 @@ export default async ({
container: MedusaContainer container: MedusaContainer
}): Promise<void> => { }): Promise<void> => {
const searchService = const searchService =
container.resolve<AbstractSearchService<never>>("searchService") container.resolve<AbstractSearchService>("searchService")
const logger = container.resolve<Logger>("logger") const logger = container.resolve<Logger>("logger")
if (searchService.isDefault) { if (searchService.isDefault) {
logger.warn( logger.warn(
+1 -1
View File
@@ -16,7 +16,7 @@ type InjectedDependencies = {
* Can authenticate a user based on email password combination * Can authenticate a user based on email password combination
* @extends BaseService * @extends BaseService
*/ */
class AuthService extends TransactionBaseService<AuthService> { class AuthService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
protected readonly userService_: UserService protected readonly userService_: UserService
+1 -1
View File
@@ -23,7 +23,7 @@ type InjectedDependencies = {
strategyResolverService: StrategyResolverService strategyResolverService: StrategyResolverService
} }
class BatchJobService extends TransactionBaseService<BatchJobService> { class BatchJobService extends TransactionBaseService {
static readonly Events = { static readonly Events = {
CREATED: "batch.created", CREATED: "batch.created",
UPDATED: "batch.updated", UPDATED: "batch.updated",
+1 -1
View File
@@ -83,7 +83,7 @@ type TotalsConfig = {
/* Provides layer to manipulate carts. /* Provides layer to manipulate carts.
* @implements BaseService * @implements BaseService
*/ */
class CartService extends TransactionBaseService<CartService> { class CartService extends TransactionBaseService {
static readonly Events = { static readonly Events = {
CUSTOMER_UPDATED: "cart.customer_updated", CUSTOMER_UPDATED: "cart.customer_updated",
CREATED: "cart.created", CREATED: "cart.created",
+1 -1
View File
@@ -11,7 +11,7 @@ import { buildQuery, setMetadata } from "../utils"
import EventBusService from "./event-bus" import EventBusService from "./event-bus"
import LineItemService from "./line-item" import LineItemService from "./line-item"
class ClaimItemService extends BaseService<ClaimItemService> { class ClaimItemService extends BaseService {
static Events = { static Events = {
CREATED: "claim_item.created", CREATED: "claim_item.created",
UPDATED: "claim_item.updated", UPDATED: "claim_item.updated",
+1 -4
View File
@@ -49,10 +49,7 @@ type InjectedDependencies = {
totalsService: TotalsService totalsService: TotalsService
} }
export default class ClaimService extends TransactionBaseService< export default class ClaimService extends TransactionBaseService {
ClaimService,
InjectedDependencies
> {
static readonly Events = { static readonly Events = {
CREATED: "claim.created", CREATED: "claim.created",
UPDATED: "claim.updated", UPDATED: "claim.updated",
@@ -11,7 +11,7 @@ type InjectedDependencies = {
manager: EntityManager manager: EntityManager
customShippingOptionRepository: typeof CustomShippingOptionRepository customShippingOptionRepository: typeof CustomShippingOptionRepository
} }
class CustomShippingOptionService extends TransactionBaseService<CustomShippingOptionService> { class CustomShippingOptionService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
protected customShippingOptionRepository_: typeof CustomShippingOptionRepository protected customShippingOptionRepository_: typeof CustomShippingOptionRepository
+1 -1
View File
@@ -22,7 +22,7 @@ type InjectedDependencies = {
/** /**
* Provides layer to manipulate customers. * Provides layer to manipulate customers.
*/ */
class CustomerService extends TransactionBaseService<CustomerService> { class CustomerService extends TransactionBaseService {
protected readonly customerRepository_: typeof CustomerRepository protected readonly customerRepository_: typeof CustomerRepository
protected readonly addressRepository_: typeof AddressRepository protected readonly addressRepository_: typeof AddressRepository
protected readonly eventBusService_: EventBusService protected readonly eventBusService_: EventBusService
@@ -27,7 +27,7 @@ type InjectedDependencies = {
* Provides layer to manipulate discount conditions. * Provides layer to manipulate discount conditions.
* @implements {BaseService} * @implements {BaseService}
*/ */
class DiscountConditionService extends TransactionBaseService<DiscountConditionService> { class DiscountConditionService extends TransactionBaseService {
protected readonly discountConditionRepository_: typeof DiscountConditionRepository protected readonly discountConditionRepository_: typeof DiscountConditionRepository
protected readonly eventBus_: EventBusService protected readonly eventBus_: EventBusService
+1 -1
View File
@@ -44,7 +44,7 @@ import { buildQuery, setMetadata } from "../utils"
* Provides layer to manipulate discounts. * Provides layer to manipulate discounts.
* @implements {BaseService} * @implements {BaseService}
*/ */
class DiscountService extends TransactionBaseService<DiscountService> { class DiscountService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
+1 -1
View File
@@ -30,7 +30,7 @@ type InjectedDependencies = {
* Handles draft orders * Handles draft orders
* @implements {BaseService} * @implements {BaseService}
*/ */
class DraftOrderService extends TransactionBaseService<DraftOrderService> { class DraftOrderService extends TransactionBaseService {
static readonly Events = { static readonly Events = {
CREATED: "draft_order.created", CREATED: "draft_order.created",
UPDATED: "draft_order.updated", UPDATED: "draft_order.updated",
+1 -1
View File
@@ -8,7 +8,7 @@ import {
UploadStreamDescriptorType, UploadStreamDescriptorType,
} from "../interfaces" } from "../interfaces"
class DefaultFileService extends AbstractFileService<any> { class DefaultFileService extends AbstractFileService {
upload(fileData: Express.Multer.File): Promise<FileServiceUploadResult> { upload(fileData: Express.Multer.File): Promise<FileServiceUploadResult> {
throw new MedusaError( throw new MedusaError(
MedusaError.Types.UNEXPECTED_STATE, MedusaError.Types.UNEXPECTED_STATE,
+1 -1
View File
@@ -32,7 +32,7 @@ type InjectedDependencies = {
/** /**
* Handles Fulfillments * Handles Fulfillments
*/ */
class FulfillmentService extends TransactionBaseService<FulfillmentService> { class FulfillmentService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
+1 -1
View File
@@ -30,7 +30,7 @@ type InjectedDependencies = {
/** /**
* Provides layer to manipulate gift cards. * Provides layer to manipulate gift cards.
*/ */
class GiftCardService extends TransactionBaseService<GiftCardService> { class GiftCardService extends TransactionBaseService {
protected readonly giftCardRepository_: typeof GiftCardRepository protected readonly giftCardRepository_: typeof GiftCardRepository
protected readonly giftCardTransactionRepo_: typeof GiftCardTransactionRepository protected readonly giftCardTransactionRepo_: typeof GiftCardTransactionRepository
protected readonly regionService_: RegionService protected readonly regionService_: RegionService
@@ -13,7 +13,7 @@ type InjectedDependencies = {
idempotencyKeyRepository: typeof IdempotencyKeyRepository idempotencyKeyRepository: typeof IdempotencyKeyRepository
} }
class IdempotencyKeyService extends TransactionBaseService<IdempotencyKeyService> { class IdempotencyKeyService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
+1 -1
View File
@@ -9,7 +9,7 @@ type InventoryServiceProps = {
manager: EntityManager manager: EntityManager
productVariantService: ProductVariantService productVariantService: ProductVariantService
} }
class InventoryService extends TransactionBaseService<InventoryService> { class InventoryService extends TransactionBaseService {
protected readonly productVariantService_: ProductVariantService protected readonly productVariantService_: ProductVariantService
protected manager_: EntityManager protected manager_: EntityManager
+1 -1
View File
@@ -14,7 +14,7 @@ type InjectedDependencies = {
eventBusService: EventBusService eventBusService: EventBusService
} }
class NoteService extends TransactionBaseService<NoteService> { class NoteService extends TransactionBaseService {
static readonly Events = { static readonly Events = {
CREATED: "note.created", CREATED: "note.created",
UPDATED: "note.updated", UPDATED: "note.updated",
+3 -3
View File
@@ -19,14 +19,14 @@ type InjectedDependencies = {
} }
type NotificationProviderKey = `noti_${string}` type NotificationProviderKey = `noti_${string}`
class NotificationService extends TransactionBaseService<NotificationService> { class NotificationService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
protected subscribers_ = {} protected subscribers_ = {}
protected attachmentGenerator_: unknown = null protected attachmentGenerator_: unknown = null
protected readonly container_: InjectedDependencies & { protected readonly container_: InjectedDependencies & {
[key in `${NotificationProviderKey}`]: AbstractNotificationService<never> [key in `${NotificationProviderKey}`]: AbstractNotificationService
} }
protected readonly logger_: Logger protected readonly logger_: Logger
protected readonly notificationRepository_: typeof NotificationRepository protected readonly notificationRepository_: typeof NotificationRepository
@@ -151,7 +151,7 @@ class NotificationService extends TransactionBaseService<NotificationService> {
* @param id - the id of the provider * @param id - the id of the provider
* @return the notification provider * @return the notification provider
*/ */
protected retrieveProvider_(id: string): AbstractNotificationService<never> { protected retrieveProvider_(id: string): AbstractNotificationService {
try { try {
return this.container_[`noti_${id}`] return this.container_[`noti_${id}`]
} catch (err) { } catch (err) {
+1 -1
View File
@@ -15,7 +15,7 @@ type InjectedDependencies = MedusaContainer & {
oauthRepository: typeof OauthRepository oauthRepository: typeof OauthRepository
} }
class Oauth extends TransactionBaseService<Oauth> { class Oauth extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
static Events = { static Events = {
+1 -1
View File
@@ -64,7 +64,7 @@ type InjectedDependencies = {
eventBusService: EventBusService eventBusService: EventBusService
} }
class OrderService extends TransactionBaseService<OrderService> { class OrderService extends TransactionBaseService {
static readonly Events = { static readonly Events = {
GIFT_CARD_CREATED: "order.gift_card_created", GIFT_CARD_CREATED: "order.gift_card_created",
PAYMENT_CAPTURED: "order.payment_captured", PAYMENT_CAPTURED: "order.payment_captured",
@@ -33,7 +33,7 @@ type InjectedDependencies = {
/** /**
* Helps retrieve payment providers * Helps retrieve payment providers
*/ */
export default class PaymentProviderService extends TransactionBaseService<PaymentProviderService> { export default class PaymentProviderService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
protected readonly container_: InjectedDependencies protected readonly container_: InjectedDependencies
+1 -1
View File
@@ -40,7 +40,7 @@ type PriceListConstructorProps = {
* Provides layer to manipulate product tags. * Provides layer to manipulate product tags.
* @extends BaseService * @extends BaseService
*/ */
class PriceListService extends TransactionBaseService<PriceListService> { class PriceListService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
+1 -1
View File
@@ -29,7 +29,7 @@ type InjectedDependencies = {
* Allows retrieval of prices. * Allows retrieval of prices.
* @extends BaseService * @extends BaseService
*/ */
class PricingService extends TransactionBaseService<PricingService> { class PricingService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
protected readonly regionService: RegionService protected readonly regionService: RegionService
@@ -7,7 +7,7 @@ import { ProductCollectionRepository } from "../repositories/product-collection"
import { ExtendedFindConfig, FindConfig, QuerySelector } from "../types/common" import { ExtendedFindConfig, FindConfig, QuerySelector } from "../types/common"
import { import {
CreateProductCollection, CreateProductCollection,
UpdateProductCollection UpdateProductCollection,
} from "../types/product-collection" } from "../types/product-collection"
import { buildQuery, setMetadata } from "../utils" import { buildQuery, setMetadata } from "../utils"
import { formatException } from "../utils/exception-formatter" import { formatException } from "../utils/exception-formatter"
@@ -23,7 +23,7 @@ type InjectedDependencies = {
/** /**
* Provides layer to manipulate product collections. * Provides layer to manipulate product collections.
*/ */
class ProductCollectionService extends TransactionBaseService<ProductCollectionService> { class ProductCollectionService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
+1 -4
View File
@@ -47,10 +47,7 @@ type InjectedDependencies = {
featureFlagRouter: FlagRouter featureFlagRouter: FlagRouter
} }
class ProductService extends TransactionBaseService< class ProductService extends TransactionBaseService {
ProductService,
InjectedDependencies
> {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
@@ -12,7 +12,7 @@ type InjectedDependencies = {
returnReasonRepository: typeof ReturnReasonRepository returnReasonRepository: typeof ReturnReasonRepository
} }
class ReturnReasonService extends TransactionBaseService<ReturnReasonService> { class ReturnReasonService extends TransactionBaseService {
protected readonly retReasonRepo_: typeof ReturnReasonRepository protected readonly retReasonRepo_: typeof ReturnReasonRepository
protected manager_: EntityManager protected manager_: EntityManager
@@ -20,7 +20,7 @@ type InjectedDependencies = {
storeService: StoreService storeService: StoreService
} }
class SalesChannelService extends TransactionBaseService<SalesChannelService> { class SalesChannelService extends TransactionBaseService {
static Events = { static Events = {
UPDATED: "sales_channel.updated", UPDATED: "sales_channel.updated",
CREATED: "sales_channel.created", CREATED: "sales_channel.created",
+1 -1
View File
@@ -7,7 +7,7 @@ type InjectedDependencies = {
manager: EntityManager manager: EntityManager
} }
export default class DefaultSearchService extends AbstractSearchService<DefaultSearchService> { export default class DefaultSearchService extends AbstractSearchService {
isDefault = true isDefault = true
protected manager_: EntityManager protected manager_: EntityManager
@@ -26,7 +26,7 @@ import RegionService from "./region"
/** /**
* Provides layer to manipulate profiles. * Provides layer to manipulate profiles.
*/ */
class ShippingOptionService extends TransactionBaseService<ShippingOptionService> { class ShippingOptionService extends TransactionBaseService {
protected readonly providerService_: FulfillmentProviderService protected readonly providerService_: FulfillmentProviderService
protected readonly regionService_: RegionService protected readonly regionService_: RegionService
protected readonly requirementRepository_: typeof ShippingOptionRequirementRepository protected readonly requirementRepository_: typeof ShippingOptionRequirementRepository
@@ -32,7 +32,7 @@ type InjectedDependencies = {
* @constructor * @constructor
* @implements {BaseService} * @implements {BaseService}
*/ */
class ShippingProfileService extends TransactionBaseService<ShippingProfileService> { class ShippingProfileService extends TransactionBaseService {
protected readonly productService_: ProductService protected readonly productService_: ProductService
protected readonly shippingOptionService_: ShippingOptionService protected readonly shippingOptionService_: ShippingOptionService
protected readonly customShippingOptionService_: CustomShippingOptionService protected readonly customShippingOptionService_: CustomShippingOptionService
+1 -1
View File
@@ -21,7 +21,7 @@ type InjectedDependencies = {
* Provides layer to manipulate store settings. * Provides layer to manipulate store settings.
* @extends BaseService * @extends BaseService
*/ */
class StoreService extends TransactionBaseService<StoreService> { class StoreService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager protected transactionManager_: EntityManager
@@ -7,26 +7,19 @@ type InjectedDependencies = {
[key: string]: unknown [key: string]: unknown
} }
export default class StrategyResolver extends TransactionBaseService< export default class StrategyResolver extends TransactionBaseService {
StrategyResolver,
InjectedDependencies
> {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
constructor(container: InjectedDependencies) { constructor(protected readonly container: InjectedDependencies) {
super(container) super(container)
this.manager_ = container.manager this.manager_ = container.manager
} }
resolveBatchJobByType<T extends TransactionBaseService<never>>( resolveBatchJobByType(type: string): AbstractBatchJobStrategy {
type: string let resolved: AbstractBatchJobStrategy
): AbstractBatchJobStrategy<T> {
let resolved: AbstractBatchJobStrategy<T>
try { try {
resolved = this.container[ resolved = this.container[`batchType_${type}`] as AbstractBatchJobStrategy
`batchType_${type}`
] as AbstractBatchJobStrategy<T>
} catch (e) { } catch (e) {
throw new MedusaError( throw new MedusaError(
MedusaError.Types.NOT_FOUND, MedusaError.Types.NOT_FOUND,
+1 -1
View File
@@ -38,7 +38,7 @@ type RegionDetails = {
/** /**
* Finds tax providers and assists in tax related operations. * Finds tax providers and assists in tax related operations.
*/ */
class TaxProviderService extends TransactionBaseService<TaxProviderService> { class TaxProviderService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager protected transactionManager_: EntityManager
+1 -1
View File
@@ -90,7 +90,7 @@ type CalculationContextOptions = {
* A service that calculates total and subtotals for orders, carts etc.. * A service that calculates total and subtotals for orders, carts etc..
* @implements {BaseService} * @implements {BaseService}
*/ */
class TotalsService extends TransactionBaseService<TotalsService> { class TotalsService extends TransactionBaseService {
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager protected transactionManager_: EntityManager
+2 -4
View File
@@ -24,7 +24,7 @@ type UserServiceProps = {
* Provides layer to manipulate users. * Provides layer to manipulate users.
* @extends BaseService * @extends BaseService
*/ */
class UserService extends TransactionBaseService<UserService> { class UserService extends TransactionBaseService {
static Events = { static Events = {
PASSWORD_RESET: "user.password_reset", PASSWORD_RESET: "user.password_reset",
CREATED: "user.created", CREATED: "user.created",
@@ -51,9 +51,7 @@ class UserService extends TransactionBaseService<UserService> {
* @return {string} the validated email * @return {string} the validated email
*/ */
validateEmail_(email: string): string { validateEmail_(email: string): string {
const schema = Validator.string() const schema = Validator.string().email().required()
.email()
.required()
const { value, error } = schema.validate(email) const { value, error } = schema.validate(email)
if (error) { if (error) {
throw new MedusaError( throw new MedusaError(
@@ -18,14 +18,14 @@ import SalesChannelFeatureFlag from "../../../loaders/feature-flags/sales-channe
import { FindConfig } from "../../../types/common" import { FindConfig } from "../../../types/common"
type InjectedDependencies = { type InjectedDependencies = {
fileService: IFileService<never> fileService: IFileService
orderService: OrderService orderService: OrderService
batchJobService: BatchJobService batchJobService: BatchJobService
manager: EntityManager manager: EntityManager
featureFlagRouter: FlagRouter featureFlagRouter: FlagRouter
} }
class OrderExportStrategy extends AbstractBatchJobStrategy<OrderExportStrategy> { class OrderExportStrategy extends AbstractBatchJobStrategy {
public static identifier = "order-export-strategy" public static identifier = "order-export-strategy"
public static batchType = "order-export" public static batchType = "order-export"
@@ -37,7 +37,7 @@ class OrderExportStrategy extends AbstractBatchJobStrategy<OrderExportStrategy>
protected manager_: EntityManager protected manager_: EntityManager
protected transactionManager_: EntityManager | undefined protected transactionManager_: EntityManager | undefined
protected readonly fileService_: IFileService<any> protected readonly fileService_: IFileService
protected readonly batchJobService_: BatchJobService protected readonly batchJobService_: BatchJobService
protected readonly orderService_: OrderService protected readonly orderService_: OrderService
protected readonly featureFlagRouter_: FlagRouter protected readonly featureFlagRouter_: FlagRouter
@@ -258,7 +258,7 @@ class OrderExportStrategy extends AbstractBatchJobStrategy<OrderExportStrategy>
await this.fileService_ await this.fileService_
.withTransaction(transactionManager) .withTransaction(transactionManager)
.delete({ key: fileKey }) .delete({ fileKey: fileKey })
return return
} }
@@ -20,14 +20,11 @@ type InjectedDependencies = {
manager: EntityManager manager: EntityManager
batchJobService: BatchJobService batchJobService: BatchJobService
productService: ProductService productService: ProductService
fileService: IFileService<never> fileService: IFileService
featureFlagRouter: FlagRouter featureFlagRouter: FlagRouter
} }
export default class ProductExportStrategy extends AbstractBatchJobStrategy< export default class ProductExportStrategy extends AbstractBatchJobStrategy {
ProductExportStrategy,
InjectedDependencies
> {
public static identifier = "product-export-strategy" public static identifier = "product-export-strategy"
public static batchType = "product-export" public static batchType = "product-export"
@@ -36,7 +33,7 @@ export default class ProductExportStrategy extends AbstractBatchJobStrategy<
protected readonly batchJobService_: BatchJobService protected readonly batchJobService_: BatchJobService
protected readonly productService_: ProductService protected readonly productService_: ProductService
protected readonly fileService_: IFileService<never> protected readonly fileService_: IFileService
protected readonly featureFlagRouter_: FlagRouter protected readonly featureFlagRouter_: FlagRouter
protected readonly defaultRelations_ = [ protected readonly defaultRelations_ = [
@@ -7,13 +7,13 @@ import { ISearchService } from "../interfaces"
type InjectedDependencies = { type InjectedDependencies = {
eventBusService: EventBusService eventBusService: EventBusService
searchService: ISearchService<never> searchService: ISearchService
productService: ProductService productService: ProductService
} }
class SearchIndexingSubscriber { class SearchIndexingSubscriber {
private readonly eventBusService_: EventBusService private readonly eventBusService_: EventBusService
private readonly searchService_: ISearchService<never> private readonly searchService_: ISearchService
private readonly productService_: ProductService private readonly productService_: ProductService
constructor({ constructor({