Feat/medusa js admin collections (#916)
* feat: Add Auth Admin routes to JS client * include api key verification for admin * add admin/collections to medusa-js * undo file changes * jsdoc Co-authored-by: olivermrbl <oliver@mrbltech.com>
This commit is contained in:
co-authored by
olivermrbl
parent
fee4e46ea7
commit
40f6e88875
@@ -0,0 +1,80 @@
|
|||||||
|
import {
|
||||||
|
AdminPostCollectionsReq,
|
||||||
|
AdminCollectionsRes,
|
||||||
|
AdminPostCollectionsCollectionReq,
|
||||||
|
AdminCollectionsDeleteRes,
|
||||||
|
AdminCollectionsListRes,
|
||||||
|
AdminGetCollectionsParams,
|
||||||
|
} from "@medusajs/medusa"
|
||||||
|
import { ResponsePromise } from "../../typings"
|
||||||
|
import BaseResource from "../base"
|
||||||
|
|
||||||
|
class AdminCollectionsResource extends BaseResource {
|
||||||
|
/**
|
||||||
|
* @description Creates a collection.
|
||||||
|
* @param payload
|
||||||
|
* @returns Created collection.
|
||||||
|
*/
|
||||||
|
create(
|
||||||
|
payload: AdminPostCollectionsReq
|
||||||
|
): ResponsePromise<AdminCollectionsRes> {
|
||||||
|
const path = `/admin/collections`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Updates a collection
|
||||||
|
* @param id id of the collection to update.
|
||||||
|
* @param payload update to apply to collection.
|
||||||
|
* @returns the updated collection.
|
||||||
|
*/
|
||||||
|
update(
|
||||||
|
id: string,
|
||||||
|
payload: AdminPostCollectionsCollectionReq
|
||||||
|
): ResponsePromise<AdminCollectionsRes> {
|
||||||
|
const path = `/admin/collections/${id}`
|
||||||
|
return this.client.request("POST", path, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description deletes a collection
|
||||||
|
* @param id id of collection to delete.
|
||||||
|
* @returns Deleted response
|
||||||
|
*/
|
||||||
|
delete(id: string): ResponsePromise<AdminCollectionsDeleteRes> {
|
||||||
|
const path = `/admin/collections/${id}`
|
||||||
|
return this.client.request("DELETE", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get a collection
|
||||||
|
* @param id id of the collection to retrieve.
|
||||||
|
* @returns the collection with the given id
|
||||||
|
*/
|
||||||
|
retrieve(id: string): ResponsePromise<AdminCollectionsListRes> {
|
||||||
|
const path = `/admin/collections/${id}`
|
||||||
|
return this.client.request("GET", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Lists collections matching a query
|
||||||
|
* @param query Query for searching collections
|
||||||
|
* @returns a list of colllections matching the query.
|
||||||
|
*/
|
||||||
|
list(
|
||||||
|
query?: AdminGetCollectionsParams
|
||||||
|
): ResponsePromise<AdminCollectionsListRes> {
|
||||||
|
let path = `/admin/collections`
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
const queryString = Object.entries(query).map(([key, value]) => {
|
||||||
|
return typeof value !== "undefined" ? `${key}=${value}` : ""
|
||||||
|
})
|
||||||
|
path = `/admin/collections?${queryString.join("&")}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.client.request("GET", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdminCollectionsResource
|
||||||
@@ -2,6 +2,7 @@ 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 CollectionsResource from "./collections"
|
||||||
import AdminDraftOrdersResource from "./draft-orders"
|
import AdminDraftOrdersResource from "./draft-orders"
|
||||||
import AdminGiftCardsResource from "./gift-cards"
|
import AdminGiftCardsResource from "./gift-cards"
|
||||||
import AdminInvitesResource from "./invites"
|
import AdminInvitesResource from "./invites"
|
||||||
@@ -11,6 +12,7 @@ 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 collections = new CollectionsResource(this.client)
|
||||||
public draftOrders = new AdminDraftOrdersResource(this.client)
|
public draftOrders = new AdminDraftOrdersResource(this.client)
|
||||||
public giftCards = new AdminGiftCardsResource(this.client)
|
public giftCards = new AdminGiftCardsResource(this.client)
|
||||||
public invites = new AdminInvitesResource(this.client)
|
public invites = new AdminInvitesResource(this.client)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export default (container, config) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Admin
|
// Admin
|
||||||
|
export * from "./routes/admin/collections"
|
||||||
export * from "./routes/admin/auth"
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user