UNPKG

shopify-admin-api

Version:

Shopify Admin API is a NodeJS library built to help developers easily authenticate and make calls against the Shopify API. It was inspired by and borrows heavily from ShopifySharp.

57 lines (56 loc) 2.14 kB
import { BaseService } from '../infrastructure'; /** * A service for manipulating Shopify Price Rules. */ export class PriceRuleDiscounts extends BaseService { constructor(shopDomain, accessToken) { super(shopDomain, accessToken, `price_rules`); } getPath(priceRuleId, path) { return this.joinUriPaths(`${priceRuleId}/discount_codes`, path); } /** * Returns a list of discount codes belonging to a specified price rule. * @param options Options for filtering the results. */ list(priceRuleId, options) { return this.createRequest("GET", this.getPath(priceRuleId, ".json"), "discount_codes", options); } /** * Creates a new discount code for a given price rule. * Note: Currently, you can only create a single discount code per price rule. */ create(priceRuleId, discount) { return this.createRequest("POST", this.getPath(priceRuleId, ".json"), "discount_code", { discount_code: discount }); } /** * Returns details about a single discount code object. */ get(priceRuleId, id) { return this.createRequest("GET", this.getPath(priceRuleId, `${id}.json`), "discount_code"); } /** * Search by discount code. * * The lookup endpoint does not return the discount code object, rather it returns the location of the * discount code in the location header. * * // https://your-store-domain.myshopify.com/admin/discount_codes/lookup?code=discountCode */ lookup(priceRuleId, code) { return this.createRequest("GET", this.getPath(priceRuleId, `discount_codes/lookup?code=${code}`)); } /** * Updates a single discount code for a given price rule. */ update(priceRuleId, id, discount) { return this.createRequest("PUT", this.getPath(priceRuleId, `${id}.json`), "discount_code", { discount_code: discount }); } /** * Deletes an existing discount code object. */ delete(priceRuleId, id) { return this.createRequest("DELETE", this.getPath(priceRuleId, `${id}.json`)); } } export default PriceRuleDiscounts;