Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/endpoints/rule-promotions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -56,7 +72,6 @@ class RulePromotionsEndpoint extends CRUDExtend {
)
}


DeleteCodes(promotionId, codes) {
return this.request.send(
`${this.endpoint}/${promotionId}/codes`,
Expand Down
42 changes: 42 additions & 0 deletions src/types/rule-promotions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
code: string
}
Expand All @@ -114,11 +149,18 @@ export interface RulePromotionsEndpoint

Codes(promotionId: string): Promise<ResourcePage<RulePromotionCode>>

Jobs(promotionId: string): Promise<ResourcePage<RulePromotionJob>>

AddCodes(
promotionId: string,
codes: RulePromotionCode[]
): Promise<Resource<RulePromotionBase>>

AddCodesJob(
promotionId: string,
body: RulePromotionCodesJob
): Promise<Resource<RulePromotionJob>>

DeleteCode(promotionId: string, codeId: string): Promise<{}>

DeleteCodes(
Expand Down