Skip to content

Commit

Permalink
chore(js-sdk,types): add tsdocs for admin JS SDK methods [6/n]
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser committed Nov 11, 2024
1 parent 82fd93d commit f872350
Show file tree
Hide file tree
Showing 18 changed files with 1,589 additions and 20 deletions.
130 changes: 130 additions & 0 deletions packages/core/js-sdk/src/admin/product-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ export class ProductTag {
this.client = client
}

/**
* This method creates a product tag. It sends a request to the
* [Create Product Tag](https://docs.medusajs.com/api/admin#product-tags_postproducttags)
* API route.
*
* @param body - The details of the product tag.
* @param query - Configure the fields to retrieve in the product tag.
* @param headers - Headers to pass in the request
* @returns The product tag's details.
*
* @example
* sdk.admin.productTag.create({
* value: "shirt"
* })
* .then(({ product_tag }) => {
* console.log(product_tag)
* })
*/
async create(
body: HttpTypes.AdminCreateProductTag,
query?: HttpTypes.AdminProductTagParams,
Expand All @@ -30,6 +48,25 @@ export class ProductTag {
)
}

/**
* This method updates a tag's details. It sends a request to the
* [Update Product Tag](https://docs.medusajs.com/api/admin#product-tags_postproducttagsid)
* API route.
*
* @param id - The tag's ID.
* @param body - The data to update in the tag.
* @param query - Configure the fields to retrieve in the product tag.
* @param headers - Headers to pass in the request
* @returns The product tag's details.
*
* @example
* sdk.admin.productTag.update("ptag_123", {
* value: "shirt"
* })
* .then(({ product_tag }) => {
* console.log(product_tag)
* })
*/
async update(
id: string,
body: HttpTypes.AdminUpdateProductTag,
Expand All @@ -47,6 +84,52 @@ export class ProductTag {
)
}

/**
* This method retrieves a paginated list of product tags. It sends a request to the
* [List Product Tags](https://docs.medusajs.com/api/admin#product-tags_getproducttags) API route.
*
* @param query - Filters and pagination configurations.
* @param headers - Headers to pass in the request.
* @returns The paginated list of product tags.
*
* @example
* To retrieve the list of product tags:
*
* ```ts
* sdk.admin.productTag.list()
* .then(({ product_tags, count, limit, offset }) => {
* console.log(product_tags)
* })
* ```
*
* To configure the pagination, pass the `limit` and `offset` query parameters.
*
* For example, to retrieve only 10 items and skip 10 items:
*
* ```ts
* sdk.admin.productTag.list({
* limit: 10,
* offset: 10
* })
* .then(({ product_tags, count, limit, offset }) => {
* console.log(product_tags)
* })
* ```
*
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
* in each product tag:
*
* ```ts
* sdk.admin.productTag.list({
* fields: "id,*products"
* })
* .then(({ product_tags, count, limit, offset }) => {
* console.log(product_tags)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
*/
async list(
query?: HttpTypes.AdminProductTagListParams,
headers?: ClientHeaders
Expand All @@ -60,6 +143,38 @@ export class ProductTag {
)
}

/**
* This method retrieves a product tag by its ID. It sends a request to the
* [Get Product Tag](https://docs.medusajs.com/api/admin#product-tags_getproducttagsid) API route.
*
* @param id - The product tag's ID.
* @param query - Configure the fields to retrieve in the product tag.
* @param headers - Headers to pass in the request
* @returns The product tag's details.
*
* @example
* To retrieve a product tag by its ID:
*
* ```ts
* sdk.admin.productTag.retrieve("ptag_123")
* .then(({ product_tag }) => {
* console.log(product_tag)
* })
* ```
*
* To specify the fields and relations to retrieve:
*
* ```ts
* sdk.admin.productTag.retrieve("ptag_123", {
* fields: "id,*products"
* })
* .then(({ product_tag }) => {
* console.log(product_tag)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
*/
async retrieve(
id: string,
query?: HttpTypes.AdminProductTagParams,
Expand All @@ -74,6 +189,21 @@ export class ProductTag {
)
}

/**
* This method deletes a product tag. It sends a request to the
* [Delete Product Tag](https://docs.medusajs.com/api/admin#product-tags_deleteproducttagsid)
* API route.
*
* @param id - The tag's ID.
* @param headers - Headers to pass in the request
* @returns The deletion's details.
*
* @example
* sdk.admin.productTag.delete("ptag_123")
* .then(({ deleted }) => {
* console.log(deleted)
* })
*/
async delete(id: string, headers?: ClientHeaders) {
return this.client.fetch<HttpTypes.AdminProductTagDeleteResponse>(
`/admin/product-tags/${id}`,
Expand Down
131 changes: 131 additions & 0 deletions packages/core/js-sdk/src/admin/product-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ export class ProductType {
this.client = client
}

/**
* This method creates a product type. It sends a request to the
* [Create Product Type](https://docs.medusajs.com/api/admin#product-types_postproducttypes)
* API route.
*
* @param body - The product type's details.
* @param query - Configure the fields to retrieve in the product type.
* @param headers - Headers to pass in the request
* @returns The product type's details.
*
* @example
* sdk.admin.productType.create({
* value: "Clothes"
* })
* .then(({ product_type }) => {
* console.log(product_type)
* })
*/
async create(
body: HttpTypes.AdminCreateProductType,
query?: HttpTypes.SelectParams,
Expand All @@ -30,6 +48,25 @@ export class ProductType {
)
}

/**
* This method updates a product type. It sends a request to the
* [Update Product Type](https://docs.medusajs.com/api/admin#product-types_postproducttypesid)
* API route.
*
* @param id - The product type's ID.
* @param body - The data to update in the product type.
* @param query - Configure the fields to retrieve in the product type.
* @param headers - Headers to pass in the request
* @returns The product type's details.
*
* @example
* sdk.admin.productType.update("ptyp_123", {
* value: "Clothes"
* })
* .then(({ product_type }) => {
* console.log(product_type)
* })
*/
async update(
id: string,
body: HttpTypes.AdminUpdateProductType,
Expand All @@ -47,6 +84,52 @@ export class ProductType {
)
}

/**
* This method retrieves a paginated list of product types. It sends a request to the
* [List Product Types](https://docs.medusajs.com/api/admin#product-types_getproducttypes) API route.
*
* @param query - Filters and pagination configurations.
* @param headers - Headers to pass in the request.
* @returns The paginated list of product types.
*
* @example
* To retrieve the list of product types:
*
* ```ts
* sdk.admin.productType.list()
* .then(({ product_types, count, limit, offset }) => {
* console.log(product_types)
* })
* ```
*
* To configure the pagination, pass the `limit` and `offset` query parameters.
*
* For example, to retrieve only 10 items and skip 10 items:
*
* ```ts
* sdk.admin.productType.list({
* limit: 10,
* offset: 10
* })
* .then(({ product_types, count, limit, offset }) => {
* console.log(product_types)
* })
* ```
*
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
* in each product type:
*
* ```ts
* sdk.admin.productType.list({
* fields: "id,*products"
* })
* .then(({ product_types, count, limit, offset }) => {
* console.log(product_types)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
*/
async list(
query?: HttpTypes.AdminProductTypeListParams,
headers?: ClientHeaders
Expand All @@ -60,6 +143,39 @@ export class ProductType {
)
}

/**
* This method retrieves a product type by its ID. It sends a request to the
* [Get Product Type](https://docs.medusajs.com/api/admin#product-types_getproducttypesid)
* API route.
*
* @param id - The product type's ID.
* @param query - Configure the fields to retrieve in the product type.
* @param headers - Headers to pass in the request
* @returns The product type's details.
*
* @example
* To retrieve a product type by its ID:
*
* ```ts
* sdk.admin.productType.retrieve("ptyp_123")
* .then(({ product_type }) => {
* console.log(product_type)
* })
* ```
*
* To specify the fields and relations to retrieve:
*
* ```ts
* sdk.admin.productType.retrieve("ptyp_123", {
* fields: "id,*products"
* })
* .then(({ product_type }) => {
* console.log(product_type)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
*/
async retrieve(
id: string,
query?: HttpTypes.AdminProductTypeParams,
Expand All @@ -74,6 +190,21 @@ export class ProductType {
)
}

/**
* This method deletes a product type. It sends a request to the
* [Delete Product Type](https://docs.medusajs.com/api/admin#product-types_deleteproducttypesid)
* API route.
*
* @param id - The product type's ID.
* @param headers - Headers to pass in the request
* @returns The product type's details.
*
* @example
* sdk.admin.productType.delete("ptyp_123")
* .then(({ deleted }) => {
* console.log(deleted)
* })
*/
async delete(id: string, headers?: ClientHeaders) {
return this.client.fetch<HttpTypes.AdminProductTypeDeleteResponse>(
`/admin/product-types/${id}`,
Expand Down
51 changes: 49 additions & 2 deletions packages/core/js-sdk/src/admin/product-variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,62 @@ export class ProductVariant {
this.client = client
}

/**
* This method retrieves a paginated list of product variants. It sends a request to the
* [List Product Variants](https://docs.medusajs.com/api/admin#product-variants_getproductvariants)
* API route.
*
* @param query - Filters and pagination configurations.
* @param headers - Headers to pass in the request.
* @returns The paginated list of product variants.
*
* @example
* To retrieve the list of product variants:
*
* ```ts
* sdk.admin.productVariant.list()
* .then(({ variants, count, limit, offset }) => {
* console.log(variants)
* })
* ```
*
* To configure the pagination, pass the `limit` and `offset` query parameters.
*
* For example, to retrieve only 10 items and skip 10 items:
*
* ```ts
* sdk.admin.productVariant.list({
* limit: 10,
* offset: 10
* })
* .then(({ variants, count, limit, offset }) => {
* console.log(variants)
* })
* ```
*
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
* in each campaign:
*
* ```ts
* sdk.admin.productVariant.list({
* fields: "id,products"
* })
* .then(({ variants, count, limit, offset }) => {
* console.log(variants)
* })
* ```
*
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
*/
async list(
queryParams?: HttpTypes.AdminProductVariantParams,
query?: HttpTypes.AdminProductVariantParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminProductVariantListResponse>(
`/admin/product-variants`,
{
headers,
query: queryParams,
query,
}
)
}
Expand Down
Loading

0 comments on commit f872350

Please sign in to comment.