UNPKG

@vendure/core

Version:

A modern, headless ecommerce framework

100 lines (99 loc) 6.27 kB
import { ApplyCouponCodeResult } from '@vendure/common/lib/generated-shop-types'; import { AssignPromotionsToChannelInput, ConfigurableOperationDefinition, CreatePromotionInput, CreatePromotionResult, DeletionResponse, RemovePromotionsFromChannelInput, UpdatePromotionInput, UpdatePromotionResult } from '@vendure/common/lib/generated-types'; import { ID, PaginatedList } from '@vendure/common/lib/shared-types'; import { RequestContext } from '../../api/common/request-context'; import { RelationPaths } from '../../api/decorators/relations.decorator'; import { ErrorResultUnion, JustErrorResults } from '../../common/error/error-result'; import { ListQueryOptions } from '../../common/types/common-types'; import { ConfigService } from '../../config/config.service'; import { PromotionAction } from '../../config/promotion/promotion-action'; import { PromotionCondition } from '../../config/promotion/promotion-condition'; import { TransactionalConnection } from '../../connection/transactional-connection'; import { Order } from '../../entity/order/order.entity'; import { Promotion } from '../../entity/promotion/promotion.entity'; import { EventBus } from '../../event-bus'; import { ConfigArgService } from '../helpers/config-arg/config-arg.service'; import { CustomFieldRelationService } from '../helpers/custom-field-relation/custom-field-relation.service'; import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder'; import { TranslatableSaver } from '../helpers/translatable-saver/translatable-saver'; import { TranslatorService } from '../helpers/translator/translator.service'; import { ChannelService } from './channel.service'; /** * @description * Contains methods relating to {@link Promotion} entities. * * @docsCategory services */ export declare class PromotionService { private connection; private configService; private channelService; private listQueryBuilder; private configArgService; private customFieldRelationService; private eventBus; private translatableSaver; private translator; availableConditions: PromotionCondition[]; availableActions: PromotionAction[]; constructor(connection: TransactionalConnection, configService: ConfigService, channelService: ChannelService, listQueryBuilder: ListQueryBuilder, configArgService: ConfigArgService, customFieldRelationService: CustomFieldRelationService, eventBus: EventBus, translatableSaver: TranslatableSaver, translator: TranslatorService); findAll(ctx: RequestContext, options?: ListQueryOptions<Promotion>, relations?: RelationPaths<Promotion>): Promise<PaginatedList<Promotion>>; findOne(ctx: RequestContext, adjustmentSourceId: ID, relations?: RelationPaths<Promotion>): Promise<Promotion | undefined>; getPromotionConditions(ctx: RequestContext): ConfigurableOperationDefinition[]; getPromotionActions(ctx: RequestContext): ConfigurableOperationDefinition[]; createPromotion(ctx: RequestContext, input: CreatePromotionInput): Promise<ErrorResultUnion<CreatePromotionResult, Promotion>>; updatePromotion(ctx: RequestContext, input: UpdatePromotionInput): Promise<ErrorResultUnion<UpdatePromotionResult, Promotion>>; softDeletePromotion(ctx: RequestContext, promotionId: ID): Promise<DeletionResponse>; assignPromotionsToChannel(ctx: RequestContext, input: AssignPromotionsToChannelInput): Promise<Promotion[]>; removePromotionsFromChannel(ctx: RequestContext, input: RemovePromotionsFromChannelInput): Promise<import("../..").Translated<Promotion>[]>; /** * @description * Checks the validity of a coupon code, by checking that it is associated with an existing, * enabled and non-expired Promotion. The comparison is case-insensitive, so e.g. "SUMMER20" * and "summer20" are treated as the same code. Additionally, if there is a usage limit on the * coupon code, this method will enforce that limit against the specified Customer. */ validateCouponCode(ctx: RequestContext, couponCode: string, customerId?: ID, excludeOrderId?: ID): Promise<JustErrorResults<ApplyCouponCodeResult> | Promotion>; getActivePromotionsInChannel(ctx: RequestContext): Promise<import("../..").Translated<Promotion>[]>; getActivePromotionsOnOrder(ctx: RequestContext, orderId: ID): Promise<Promotion[]>; runPromotionSideEffects(ctx: RequestContext, order: Order, promotionsPre: Promotion[]): Promise<void>; /** * @description * Used internally to associate a Promotion with an Order, once an Order has been placed. * * @deprecated This method is no longer used and will be removed in v2.0 */ addPromotionsToOrder(ctx: RequestContext, order: Order): Promise<Order>; /** * @description * Returns a Set of Promotion IDs (as strings) that have exceeded their `usageLimit` or * `perCustomerUsageLimit`. Only checks promotions without a coupon code * (coupon-based promotions are validated separately in `validateCouponCode()`). */ getExhaustedPromotionIds(ctx: RequestContext, promotions: Promotion[], customerId?: ID): Promise<Set<string>>; /** * Returns a base query builder for counting promotion usages on placed orders. * Excludes cancelled orders, draft orders, active (un-placed) orders, and * seller-type orders. */ private placedOrdersWithPromotionQb; private getUsageCountsBatch; /** * Counts the number of times a promotion has been used by the given * customer, including orders currently in the `ArrangingPayment` state * (excluding the given order). Mirrors `countPromotionUsages` so that * `perCustomerUsageLimit` is enforced under the same TOCTOU-safe * semantics as `usageLimit`. */ private countPromotionUsagesForCustomer; /** * Counts the number of times a promotion has been used, including orders * currently in the ArrangingPayment state (excluding the given order). * The ArrangingPayment count prevents concurrent checkouts from bypassing * the usage limit via a TOCTOU race condition. * See https://github.com/vendurehq/vendure/pull/4660 */ private countPromotionUsages; private calculatePriorityScore; private validateRequiredConditions; }