Adds admin giftcard API to medusa-js (#921)
This commit is contained in:
1 parent
006e67eea1
commit
85ef51ad34
3 files changed
+71
No files matched your search
@@ -0,0 +1,66 @@
|
|||||||
|
import {
|
||||||
|
AdminGetGiftCardsParams,
|
||||||
|
AdminGiftCardsDeleteRes,
|
||||||
|
AdminGiftCardsListRes,
|
||||||
|
AdminGiftCardsRes,
|
||||||
|
AdminPostGiftCardsGiftCardReq,
|
||||||
|
AdminPostGiftCardsReq,
|
||||||
|
} from "@medusajs/medusa"
|
||||||
|
import { ResponsePromise } from "../../typings"
|
||||||
|
import BaseResource from "../base"
|
||||||
|
|
||||||
|
class AdminGiftCardsResource extends BaseResource {
|
||||||
|
/**
|
||||||
|
* @description Creates a gift card
|
||||||
|
*/
|
||||||
|
create(payload: AdminPostGiftCardsReq): ResponsePromise<AdminGiftCardsRes> {
|
||||||
|
const path = `/admin/gift-cards`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Updates a gift card
|
||||||
|
*/
|
||||||
|
update(
|
||||||
|
id: string,
|
||||||
|
payload: AdminPostGiftCardsGiftCardReq
|
||||||
|
): ResponsePromise<AdminGiftCardsRes> {
|
||||||
|
const path = `/admin/gift-cards/${id}`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Deletes a gift card
|
||||||
|
*/
|
||||||
|
delete(id: string): ResponsePromise<AdminGiftCardsDeleteRes> {
|
||||||
|
const path = `/admin/gift-cards/${id}`
|
||||||
|
return this.client.request("DELETE", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Deletes a gift card
|
||||||
|
*/
|
||||||
|
retrieve(id: string): ResponsePromise<AdminGiftCardsRes> {
|
||||||
|
const path = `/admin/gift-cards/${id}`
|
||||||
|
return this.client.request("GET", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Lists gift cards
|
||||||
|
*/
|
||||||
|
list(query: AdminGetGiftCardsParams): ResponsePromise<AdminGiftCardsListRes> {
|
||||||
|
let path = `/admin/gift-cards/`
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
const queryString = Object.entries(query).map(([key, value]) => {
|
||||||
|
return `${key}=${value}`
|
||||||
|
})
|
||||||
|
|
||||||
|
path = `/admin/gift-cards?${queryString.join("&")}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.client.request("GET", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdminGiftCardsResource
|
||||||
@@ -2,6 +2,8 @@ import BaseResource from "../base"
|
|||||||
import AdminAuthResource from "./auth"
|
import AdminAuthResource from "./auth"
|
||||||
import AdminCustomersResource from "./customers"
|
import AdminCustomersResource from "./customers"
|
||||||
import AdminDiscountsResource from "./discounts"
|
import AdminDiscountsResource from "./discounts"
|
||||||
|
import AdminDraftOrdersResource from "./draft-orders"
|
||||||
|
import AdminGiftCardsResource from "./gift-cards"
|
||||||
import AdminInvitesResource from "./invites"
|
import AdminInvitesResource from "./invites"
|
||||||
import AdminNotesResource from "./notes"
|
import AdminNotesResource from "./notes"
|
||||||
|
|
||||||
@@ -9,6 +11,8 @@ class Admin extends BaseResource {
|
|||||||
public auth = new AdminAuthResource(this.client)
|
public auth = new AdminAuthResource(this.client)
|
||||||
public customers = new AdminCustomersResource(this.client)
|
public customers = new AdminCustomersResource(this.client)
|
||||||
public discounts = new AdminDiscountsResource(this.client)
|
public discounts = new AdminDiscountsResource(this.client)
|
||||||
|
public draftOrders = new AdminDraftOrdersResource(this.client)
|
||||||
|
public giftCards = new AdminGiftCardsResource(this.client)
|
||||||
public invites = new AdminInvitesResource(this.client)
|
public invites = new AdminInvitesResource(this.client)
|
||||||
public notes = new AdminNotesResource(this.client)
|
public notes = new AdminNotesResource(this.client)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export * from "./routes/admin/auth"
|
|||||||
export * from "./routes/admin/customers"
|
export * from "./routes/admin/customers"
|
||||||
export * from "./routes/admin/discounts"
|
export * from "./routes/admin/discounts"
|
||||||
export * from "./routes/admin/draft-orders"
|
export * from "./routes/admin/draft-orders"
|
||||||
|
export * from "./routes/admin/gift-cards"
|
||||||
export * from "./routes/admin/invites"
|
export * from "./routes/admin/invites"
|
||||||
export * from "./routes/admin/notes"
|
export * from "./routes/admin/notes"
|
||||||
export * from "./routes/admin/notifications"
|
export * from "./routes/admin/notifications"
|
||||||
|
|||||||
Reference in new issue
Block a user