import * as Options from "../options"; import { BaseService } from "../infrastructure"; import { DraftOrder } from "../interfaces"; /** * A service for manipulating Shopify draft orders. */ export class DraftOrders extends BaseService { constructor(shopDomain: string, accessToken: string) { super(shopDomain, accessToken, "draft_orders"); } /** * Creates a new draft order. */ public create(order: Partial, useCustomerDefaultAddress: boolean = false) { const body = { ...order, use_customer_default_address: useCustomerDefaultAddress }; return this.createRequest("POST", ".json", "draft_order", { draft_order: body }); } /** * Updates the draft order with the given id. */ public update(id: number, order: Partial) { return this.createRequest("PUT", `${id}.json`, "draft_order", { draft_order: order }); } /** * Gets a list of up to 250 of the shop's draft orders. * @param options Options for filtering the results. */ public list(options?: Options.ListOptions) { return this.createRequest("GET", ".json", "draft_orders", options); } /** * Counts the draft orders on the shop. */ public count(options?: any) { return this.createRequest("GET", "count.json", "count"); } /** * Retrieves the draft order with the given id. */ public get(id: number) { return this.createRequest("GET", `${id}.json`, "draft_order"); } /** * Deletes the draft order with the given id. */ public delete(id: number) { return this.createRequest("DELETE", `${id}.json`); } /** * Completes the draft order, transitioning it to a full order. */ public complete(id: number, paymentPending: boolean = false) { return this.createRequest( "POST", `${id}/complete.json?paymentPending=${paymentPending}`, "draft_order" ); } // TODO: Implement DraftOrders.sendInvoice } export default DraftOrders;