From 6e77cb84317dec2ee21710f394586dc891e1af3c Mon Sep 17 00:00:00 2001 From: yasamanloghman <130011231+yasamanloghman@users.noreply.github.com> Date: Tue, 19 Mar 2024 13:48:47 -0400 Subject: [PATCH] feat: add codes to promotion builder (#922) * feat: add codes to promotion builder * fix: spacing --- src/endpoints/rule-promotions.js | 42 ++++++++++++++++++++++++++++++++ src/types/promotions.d.ts | 6 ++--- src/types/rule-promotions.ts | 31 +++++++++++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/endpoints/rule-promotions.js b/src/endpoints/rule-promotions.js index bef3f2fc7..da589fc85 100644 --- a/src/endpoints/rule-promotions.js +++ b/src/endpoints/rule-promotions.js @@ -1,4 +1,5 @@ import CRUDExtend from '../extends/crud' +import { buildURL } from '../utils/helpers' class RulePromotionsEndpoint extends CRUDExtend { constructor(endpoint) { @@ -25,5 +26,46 @@ class RulePromotionsEndpoint extends CRUDExtend { token ) } + + Codes(promotionId, token = null) { + const { limit, offset, filter } = this + return this.request.send( + buildURL(`${this.endpoint}/${promotionId}/codes`, { + limit, + offset, + filter + }), + 'GET', + undefined, + token, + this + ) + } + + AddCodes(promotionId, codes) { + return this.request.send(`${this.endpoint}/${promotionId}/codes`, 'POST', { + type: 'promotion_codes', + codes + }) + } + + DeleteCode(promotionId, codeId) { + return this.request.send( + `${this.endpoint}/${promotionId}/codes/${codeId}`, + 'DELETE' + ) + } + + + DeleteCodes(promotionId, codes) { + return this.request.send( + `${this.endpoint}/${promotionId}/codes`, + 'DELETE', + { + type: 'promotion_codes', + codes + } + ) + } } export default RulePromotionsEndpoint diff --git a/src/types/promotions.d.ts b/src/types/promotions.d.ts index 66721220e..adb177264 100644 --- a/src/types/promotions.d.ts +++ b/src/types/promotions.d.ts @@ -190,9 +190,9 @@ export interface PromotionCode { code: string uses?: number user?: string - created_by ?: string - max_uses ?: number - meta ?: PromotionMeta + created_by?: string + max_uses?: number + meta?: PromotionMeta consume_unit?: 'per_cart' | 'per_item' } diff --git a/src/types/rule-promotions.ts b/src/types/rule-promotions.ts index 5b9a71fa8..8ee9d0220 100644 --- a/src/types/rule-promotions.ts +++ b/src/types/rule-promotions.ts @@ -7,6 +7,9 @@ import { CrudQueryableResource, Identifiable, + ResourceList, + ResourcePage, + Resource } from './core' export interface ActionLimitation { @@ -73,6 +76,20 @@ import { 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 RulePromotionsEndpoint extends CrudQueryableResource< @@ -84,4 +101,18 @@ import { 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<{}> }