Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
feat: add codes to promotion builder (#922)
Browse files Browse the repository at this point in the history
* feat: add codes to promotion builder

* fix: spacing
  • Loading branch information
yasamanloghman authored Mar 19, 2024
1 parent 927bb84 commit 6e77cb8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
42 changes: 42 additions & 0 deletions src/endpoints/rule-promotions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CRUDExtend from '../extends/crud'
import { buildURL } from '../utils/helpers'

class RulePromotionsEndpoint extends CRUDExtend {
constructor(endpoint) {
Expand All @@ -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
6 changes: 3 additions & 3 deletions src/types/promotions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
31 changes: 31 additions & 0 deletions src/types/rule-promotions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import {
CrudQueryableResource,
Identifiable,
ResourceList,
ResourcePage,
Resource
} from './core'

export interface ActionLimitation {
Expand Down Expand Up @@ -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<any> {
code: string
}

export interface RulePromotionsEndpoint
extends CrudQueryableResource<
Expand All @@ -84,4 +101,18 @@ import {
never
> {
endpoint: 'rule-promotions'

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

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

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

DeleteCodes(
promotionId: string,
codes: DeleteRulePromotionCodes[]
): Promise<{}>
}

0 comments on commit 6e77cb8

Please sign in to comment.