Skip to content

Commit

Permalink
Add addProducts and removeProducts to AdminCollectionsResource
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Ward authored and olivermrbl committed Aug 7, 2022
1 parent 42ed209 commit adc4fed
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/medusa-js/src/resources/admin/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
AdminCollectionsDeleteRes,
AdminCollectionsListRes,
AdminGetCollectionsParams,
AdminPostProductsToCollectionReq,
AdminDeleteProductsFromCollectionReq,
} from "@medusajs/medusa"
import qs from "qs"
import { ResponsePromise } from "../../typings"
Expand Down Expand Up @@ -88,6 +90,36 @@ class AdminCollectionsResource extends BaseResource {

return this.client.request("GET", path, undefined, {}, customHeaders)
}

/**
* @description Updates products associated with a Product Collection
* @param id the id of the Collection
* @param payload - an object which contains an array of Product IDs to add to the Product Collection
* @param customHeaders
*/
addProducts(
id: string,
payload: AdminPostProductsToCollectionReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminCollectionsRes> {
const path = `/admin/collections/${id}/products/batch`
return this.client.request("POST", path, payload, {}, customHeaders)
}

/**
* @description Removes products associated with a Product Collection
* @param id - the id of the Collection
* @param payload - an object which contains an array of Product IDs to add to the Product Collection
* @param customHeaders
*/
removeProducts(
id: string,
payload: AdminDeleteProductsFromCollectionReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminCollectionsDeleteRes> {
const path = `/admin/collections/${id}/products/batch`
return this.client.request("DELETE", path, payload, {}, customHeaders)
}
}

export default AdminCollectionsResource

0 comments on commit adc4fed

Please sign in to comment.