From adc4fed992fbce04ef24093b0bb1005c6a9af73a Mon Sep 17 00:00:00 2001 From: Richard Ward Date: Mon, 1 Aug 2022 21:42:06 +0200 Subject: [PATCH] Add addProducts and removeProducts to AdminCollectionsResource --- .../src/resources/admin/collections.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/medusa-js/src/resources/admin/collections.ts b/packages/medusa-js/src/resources/admin/collections.ts index 3b161dd335fdb..b42d2cceedf7d 100644 --- a/packages/medusa-js/src/resources/admin/collections.ts +++ b/packages/medusa-js/src/resources/admin/collections.ts @@ -5,6 +5,8 @@ import { AdminCollectionsDeleteRes, AdminCollectionsListRes, AdminGetCollectionsParams, + AdminPostProductsToCollectionReq, + AdminDeleteProductsFromCollectionReq, } from "@medusajs/medusa" import qs from "qs" import { ResponsePromise } from "../../typings" @@ -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 = {} + ): ResponsePromise { + 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 = {} + ): ResponsePromise { + const path = `/admin/collections/${id}/products/batch` + return this.client.request("DELETE", path, payload, {}, customHeaders) + } } export default AdminCollectionsResource