@withpotter/discount — module reference

HTTP routes this module mounts, plus its internal use-cases, entities, and repositories. The exhaustive request/response contract is the engine’s OpenAPI document at /docs; the layered structure below follows the package internal architecture.

HTTP routes

Discounts /discounts

MethodPathAuthDescription
GET/discountsYesList discounts with filters
GET/discounts/:idYesGet discount by ID
GET/discounts/:id/analyticsYesGet discount analytics
GET/discounts/auto-applyGet auto-apply discounts for storefront
GET/discounts/code/:codeYesGet discount by code
POST/discountsYesCreate a new discount
POST/discounts/apply/:codeApply a discount code (increments usage)
POST/discounts/validateValidate a discount code
PUT/discounts/:idYesUpdate discount
PATCH/discounts/:id/activateYesActivate discount
PATCH/discounts/:id/deactivateYesDeactivate discount
DELETE/discounts/:idYesDelete discount

Internals

Use-cases

Application operations. Each is a single-purpose class with one execute() method.

Use-caseSignature
ActivateDiscountUseCaseexecute(tenantId: string, id: string): Promise<DiscountResponseDto>
ApplyDiscountUseCaseexecute(tenantId: string, code: string): Promise<DiscountResponseDto>
CreateDiscountUseCaseexecute(tenantId: string, dto: CreateDiscountDto): Promise<DiscountResponseDto>
DeactivateDiscountUseCaseexecute(tenantId: string, id: string): Promise<DiscountResponseDto>
DeleteDiscountUseCaseexecute(tenantId: string, id: string): Promise<void>
FindAutoApplyDiscountUseCaseexecute(tenantId: string): Promise<DiscountResponseDto[]>
GetDiscountAnalyticsUseCaseexecute(tenantId: string, discountId: string): Promise<DiscountAnalyticsResult>
GetDiscountByCodeUseCaseexecute(tenantId: string, code: string): Promise<DiscountResponseDto>
GetDiscountUseCaseexecute(tenantId: string, id: string): Promise<DiscountResponseDto>
ListDiscountsUseCaseexecute(tenantId: string, query: DiscountQueryDto): Promise<PaginatedDiscountsResponseDto>
UpdateDiscountUseCaseexecute(tenantId: string, id: string, dto: UpdateDiscountDto): Promise<DiscountResponseDto>
ValidateDiscountUseCaseexecute(tenantId: string, dto: ValidateDiscountDto): Promise<DiscountValidationResultDto>

Entities

Sequelize models owned by this module.

Discount — table discounts

FieldType
idstring
tenantIdstring
tenantTenant
namestring
descriptionstring | null
codestring
discountTypeDiscountType
valuenumber | null
maxDiscountAmountnumber | null
buyXGetYConfigBuyXGetYConfig | null
conditionsDiscountConditions
startsAtDate | null
endsAtDate | null
usageLimitnumber | null
usageCountnumber
usageLimitPerCustomernumber | null
statusDiscountStatus
autoApplyboolean
createdAtDate
updatedAtDate

Repositories

Data-access classes wrapping the entities.

DiscountRepository

findById · findByCode · findWithFilters · findActiveDiscounts · findAutoApply · isCodeUnique · create · update · delete · incrementUsage · decrementUsage · activate · deactivate · updateExpiredDiscounts · updateScheduledDiscounts

Generated from the module’s source. Routes are relative to the engine root (default http://localhost:3001). For full request/response schemas use the live OpenAPI document.