From 31fad7439cc4b95e269e7b6bc5d813cb2479329c Mon Sep 17 00:00:00 2001 From: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com> Date: Thu, 16 Dec 2021 16:14:58 +0100 Subject: [PATCH] feat: add store admin endpoints to medusa-js (#938) * add: store admin endpoint to medusa-js * add: resource to admin class Co-authored-by: Sebastian Rindom Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> --- .../medusa-js/src/resources/admin/index.ts | 2 + .../medusa-js/src/resources/admin/store.ts | 59 +++++++++++++++++++ packages/medusa/src/api/index.js | 1 + .../src/api/routes/admin/store/index.ts | 2 + .../api/routes/admin/store/remove-currency.ts | 2 +- 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 packages/medusa-js/src/resources/admin/store.ts diff --git a/packages/medusa-js/src/resources/admin/index.ts b/packages/medusa-js/src/resources/admin/index.ts index 609962a3af..1d77a95a29 100644 --- a/packages/medusa-js/src/resources/admin/index.ts +++ b/packages/medusa-js/src/resources/admin/index.ts @@ -13,6 +13,7 @@ import AdminReturnReasonsResource from "./return-reasons" import AdminVariantsResource from "./variants" import AdminSwapsResource from "./swaps" import AdminShippingProfilesResource from "./shipping-profiles" +import AdminStoresResource from "./store" import AdminShippingOptionsResource from "./shipping-options" import AdminRegionsResource from "./regions" @@ -31,6 +32,7 @@ class Admin extends BaseResource { public variants = new AdminVariantsResource(this.client) public swaps = new AdminSwapsResource(this.client) public shippingProfiles = new AdminShippingProfilesResource(this.client) + public store = new AdminStoresResource(this.client) public shippingOptions = new AdminShippingOptionsResource(this.client) public regions = new AdminRegionsResource(this.client) } diff --git a/packages/medusa-js/src/resources/admin/store.ts b/packages/medusa-js/src/resources/admin/store.ts new file mode 100644 index 0000000000..98642309f8 --- /dev/null +++ b/packages/medusa-js/src/resources/admin/store.ts @@ -0,0 +1,59 @@ +import { + AdminPaymentProvidersList, + AdminPostStoreReq, + AdminStoresRes, +} from "@medusajs/medusa" +import { ResponsePromise } from "../../typings" +import BaseResource from "../base" + +class AdminStoresResource extends BaseResource { + /** + * @description Updates the store + * @param payload update to apply to the store. + * @returns the updated store. + */ + update(payload: AdminPostStoreReq): ResponsePromise { + const path = `/admin/store/` + return this.client.request("POST", path, payload) + } + + /** + * @description adds a currency to the store. + * @param currency_code code of the currency to add + * @returns updated store. + */ + addCurrency(currency_code: string): ResponsePromise { + const path = `/admin/store/${currency_code}` + return this.client.request("POST", path) + } + + /** + * @description deletes a currency from the available store currencies + * @param currency_code currency code of the currency to delete from the store. + * @returns updated store + */ + deleteCurrency(currency_code: string): ResponsePromise { + const path = `/admin/store/currencies/${currency_code}` + return this.client.request("DELETE", path) + } + + /** + * @description gets a medusa store + * @returns a medusa store + */ + retrieve(): ResponsePromise { + const path = `/admin/store/` + return this.client.request("GET", path) + } + + /** + * @description Lists the store's payment providers + * @returns a list of payment providers configured on the store + */ + listPaymentProviders(): ResponsePromise { + const path = `/admin/store/payment-providers` + return this.client.request("GET", path) + } +} + +export default AdminStoresResource diff --git a/packages/medusa/src/api/index.js b/packages/medusa/src/api/index.js index 627e69d83f..3d51434736 100644 --- a/packages/medusa/src/api/index.js +++ b/packages/medusa/src/api/index.js @@ -31,6 +31,7 @@ export * from "./routes/admin/orders" export * from "./routes/admin/variants" export * from "./routes/admin/return-reasons" export * from "./routes/admin/swaps" +export * from "./routes/admin/store" export * from "./routes/admin/returns" export * from "./routes/admin/shipping-options" export * from "./routes/admin/regions" diff --git a/packages/medusa/src/api/routes/admin/store/index.ts b/packages/medusa/src/api/routes/admin/store/index.ts index 1847b38ce3..a9234a00f2 100644 --- a/packages/medusa/src/api/routes/admin/store/index.ts +++ b/packages/medusa/src/api/routes/admin/store/index.ts @@ -32,3 +32,5 @@ export type AdminStoresRes = { export type AdminPaymentProvidersList = { payment_providers: PaymentProvider[] } + +export * from "./update-store" diff --git a/packages/medusa/src/api/routes/admin/store/remove-currency.ts b/packages/medusa/src/api/routes/admin/store/remove-currency.ts index 7ff9a9f184..49dd6bc066 100644 --- a/packages/medusa/src/api/routes/admin/store/remove-currency.ts +++ b/packages/medusa/src/api/routes/admin/store/remove-currency.ts @@ -3,7 +3,7 @@ import { StoreService } from "../../../../services" /** * @oas [delete] /store/currencies/{code} * operationId: "DeleteStoreCurrenciesCode" - * summary: "Remvoe a Currency Code" + * summary: "Remove a Currency Code" * description: "Removes a Currency Code from the available currencies." * x-authenticated: true * parameters: