diff --git a/src/endpoints/rule-promotions.js b/src/endpoints/rule-promotions.js index da589fc..698e1f0 100644 --- a/src/endpoints/rule-promotions.js +++ b/src/endpoints/rule-promotions.js @@ -42,12 +42,28 @@ class RulePromotionsEndpoint extends CRUDExtend { ) } + Jobs(promotionId) { + const { limit, offset, filter } = this + return this.request.send( + buildURL(`${this.endpoint}/${promotionId}/jobs`, { + limit, + offset, + filter + }), + 'GET' + ) + } + AddCodes(promotionId, codes) { return this.request.send(`${this.endpoint}/${promotionId}/codes`, 'POST', { type: 'promotion_codes', codes }) } + + AddCodesJob(promotionId, body) { + return this.request.send(`${this.endpoint}/${promotionId}/jobs`, 'POST', body) + } DeleteCode(promotionId, codeId) { return this.request.send( @@ -56,7 +72,6 @@ class RulePromotionsEndpoint extends CRUDExtend { ) } - DeleteCodes(promotionId, codes) { return this.request.send( `${this.endpoint}/${promotionId}/codes`, diff --git a/src/types/rule-promotions.ts b/src/types/rule-promotions.ts index 686007c..6920ebc 100644 --- a/src/types/rule-promotions.ts +++ b/src/types/rule-promotions.ts @@ -89,6 +89,41 @@ export interface RulePromotionCode { consume_unit?: 'per_application' | 'per_checkout' } +export interface RulePromotionCodesJob { + type: 'promotion_job' + job_type: 'code_generate' | 'code_export' + name?: string + parameters?: { + number_of_codes: number + consume_unit?: 'per_cart' | 'per_item' + code_prefix?: string + max_uses_per_code?: number + code_length: number + } +} + +export interface RulePromotionJob extends Identifiable { + type: string + id: string + promotion_id: string + job_type: string + name?: string + parameters?: { + number_of_codes: number + consume_unit?: 'per_cart' | 'per_item' + max_uses_per_code?: number + code_length: number + code_prefix?: string + } + status: 'pending' | 'processing' | 'completed' | 'failed' + meta: { + timestamps: { + created_at: string + updated_at: string + } + } +} + export interface DeleteRulePromotionCodes extends ResourceList { code: string } @@ -114,11 +149,18 @@ export interface RulePromotionsEndpoint Codes(promotionId: string): Promise> + Jobs(promotionId: string): Promise> + AddCodes( promotionId: string, codes: RulePromotionCode[] ): Promise> + AddCodesJob( + promotionId: string, + body: RulePromotionCodesJob + ): Promise> + DeleteCode(promotionId: string, codeId: string): Promise<{}> DeleteCodes(