diff --git a/packages/medusa-js/src/resources/admin/gift-cards.ts b/packages/medusa-js/src/resources/admin/gift-cards.ts new file mode 100644 index 0000000000..eff9d4a964 --- /dev/null +++ b/packages/medusa-js/src/resources/admin/gift-cards.ts @@ -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 { + const path = `/admin/gift-cards` + return this.client.request("POST", path, payload) + } + + /** + * @description Updates a gift card + */ + update( + id: string, + payload: AdminPostGiftCardsGiftCardReq + ): ResponsePromise { + const path = `/admin/gift-cards/${id}` + return this.client.request("POST", path, payload) + } + + /** + * @description Deletes a gift card + */ + delete(id: string): ResponsePromise { + const path = `/admin/gift-cards/${id}` + return this.client.request("DELETE", path) + } + + /** + * @description Deletes a gift card + */ + retrieve(id: string): ResponsePromise { + const path = `/admin/gift-cards/${id}` + return this.client.request("GET", path) + } + + /** + * @description Lists gift cards + */ + list(query: AdminGetGiftCardsParams): ResponsePromise { + 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 diff --git a/packages/medusa-js/src/resources/admin/index.ts b/packages/medusa-js/src/resources/admin/index.ts index 44e78f8979..8c8be33b67 100644 --- a/packages/medusa-js/src/resources/admin/index.ts +++ b/packages/medusa-js/src/resources/admin/index.ts @@ -2,6 +2,8 @@ import BaseResource from "../base" import AdminAuthResource from "./auth" import AdminCustomersResource from "./customers" import AdminDiscountsResource from "./discounts" +import AdminDraftOrdersResource from "./draft-orders" +import AdminGiftCardsResource from "./gift-cards" import AdminInvitesResource from "./invites" import AdminNotesResource from "./notes" @@ -9,6 +11,8 @@ class Admin extends BaseResource { public auth = new AdminAuthResource(this.client) public customers = new AdminCustomersResource(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 notes = new AdminNotesResource(this.client) } diff --git a/packages/medusa/src/api/index.js b/packages/medusa/src/api/index.js index 33ccaf6e98..091f59623b 100644 --- a/packages/medusa/src/api/index.js +++ b/packages/medusa/src/api/index.js @@ -20,6 +20,7 @@ export * from "./routes/admin/auth" export * from "./routes/admin/customers" export * from "./routes/admin/discounts" export * from "./routes/admin/draft-orders" +export * from "./routes/admin/gift-cards" export * from "./routes/admin/invites" export * from "./routes/admin/notes" export * from "./routes/admin/notifications"