From a2b4e81df435d22977d0f4d2d7fdc59568b1e2d1 Mon Sep 17 00:00:00 2001 From: Ella Nan <38847123+ellanan@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:02:06 -0400 Subject: [PATCH] add RulePromotionFilter type --- src/types/rule-promotions.ts | 210 ++++++++++++++++++----------------- 1 file changed, 109 insertions(+), 101 deletions(-) diff --git a/src/types/rule-promotions.ts b/src/types/rule-promotions.ts index 4e3735f..bb4e524 100644 --- a/src/types/rule-promotions.ts +++ b/src/types/rule-promotions.ts @@ -5,116 +5,124 @@ * or require codes, which are then used by the end user to get a discount. */ import { - CrudQueryableResource, - Identifiable, - ResourceList, - ResourcePage, - Resource - } from './core' - - export interface ActionLimitation { - max_discount?: number - max_quantity?: number - items?: { - max_items?: number - price_strategy?: string - } + CrudQueryableResource, + Identifiable, + ResourceList, + ResourcePage, + Resource +} from './core' + +export interface ActionLimitation { + max_discount?: number + max_quantity?: number + items?: { + max_items?: number + price_strategy?: string } +} - export interface ActionCondition { - strategy: string +export interface ActionCondition { + strategy: string + operator?: string + args?: any[] + children?: { + strategy?: string operator?: string args?: any[] - children?: { - strategy?: string - operator?: string - args?: any[] - }[] - } + }[] +} - export interface Action { - strategy: string - args: any[] - limitations?: ActionLimitation - condition?: ActionCondition - } +export interface Action { + strategy: string + args: any[] + limitations?: ActionLimitation + condition?: ActionCondition +} - export interface Condition { - strategy: string - operator?: string - args?: any[] - children?: Condition[] - } +export interface Condition { + strategy: string + operator?: string + args?: any[] + children?: Condition[] +} - /** - * Promotions Builder - * Description:Base Promotion Type - */ - export interface RulePromotionBase { - type: 'rule_promotion' - name: string - description: string - enabled: boolean - automatic?: boolean - start: string - end: string - stackable: boolean - priority?: number | null | undefined - rule_set: { - currencies: string[] - catalog_ids: string[] - rules: Condition - actions: Action[] - } - } - - export interface RulePromotionMeta { - timestamps: { - created_at: string - updated_at: string - } - } - - export interface RulePromotion extends Identifiable, RulePromotionBase { - meta: RulePromotionMeta +/** + * Promotions Builder + * Description:Base Promotion Type + */ +export interface RulePromotionBase { + type: 'rule_promotion' + name: string + description: string + enabled: boolean + automatic?: boolean + start: string + end: string + stackable: boolean + priority?: number | null | undefined + rule_set: { + currencies: string[] + catalog_ids: string[] + rules: Condition + actions: Action[] } +} - export interface RulePromotionCode { - code: string - uses?: number - user?: string - created_by?: string - max_uses?: number - meta?: RulePromotionMeta - consume_unit?: 'per_application' | 'per_checkout' +export interface RulePromotionMeta { + timestamps: { + created_at: string + updated_at: string } +} - export interface DeleteRulePromotionCodes extends ResourceList { - code: string - } - - export interface RulePromotionsEndpoint - extends CrudQueryableResource< - RulePromotion, - RulePromotionBase, - Partial, - never, - never, - never - > { - endpoint: 'rule-promotions' - - Codes(promotionId: string): Promise> - - AddCodes( - promotionId: string, - codes: RulePromotionCode[] - ): Promise> - - DeleteCode(promotionId: string, codeId: string): Promise<{}> - - DeleteCodes( - promotionId: string, - codes: DeleteRulePromotionCodes[] - ): Promise<{}> +export interface RulePromotion extends Identifiable, RulePromotionBase { + meta: RulePromotionMeta +} + +export interface RulePromotionCode { + code: string + uses?: number + user?: string + created_by?: string + max_uses?: number + meta?: RulePromotionMeta + consume_unit?: 'per_application' | 'per_checkout' +} + +export interface DeleteRulePromotionCodes extends ResourceList { + code: string +} + +export interface RulePromotionFilter { + eq?: { + code?: string } +} + +export interface RulePromotionsEndpoint + extends CrudQueryableResource< + RulePromotion, + RulePromotionBase, + Partial, + RulePromotionFilter, + never, + never + > { + endpoint: 'rule-promotions' + + Filter(filter: RulePromotionFilter): RulePromotionsEndpoint + + Codes(promotionId: string): Promise> + + AddCodes( + promotionId: string, + codes: RulePromotionCode[] + ): Promise> + + DeleteCode(promotionId: string, codeId: string): Promise<{}> + + DeleteCodes( + promotionId: string, + codes: DeleteRulePromotionCodes[] + ): Promise<{}> +}