Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
Fixed Fulfillment Support and Added Product Variant Support (#24)
Browse files Browse the repository at this point in the history
* Adding fulfillment support

* Removing options references

* Adding casting

* Revert "Adding casting"

This reverts commit d04956c.

* Found serious errors in my previous PR

* add product variants service and export

* Adding proper variant support

* Fixing update
  • Loading branch information
jdalrymple authored and nozzlegear committed May 2, 2018
1 parent 6a2ce3e commit 0dce9a8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 13 deletions.
30 changes: 17 additions & 13 deletions services/fulfillments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { BaseService } from '../infrastructure';
*/
export class Fulfillments extends BaseService {
constructor(shopDomain: string, accessToken: string) {
super(shopDomain, accessToken, "");
super(shopDomain, accessToken, "orders");
}

private getPath(orderId: number, path: string) {
return this.joinUriPaths(`${orderId}/fulfillments`, path);
}

/**
Expand All @@ -16,7 +20,7 @@ export class Fulfillments extends BaseService {
* @param fulfillment The fulfillment being created.
*/
public create(orderId: number, fulfillment: Fulfillment) {
return this.createRequest<Fulfillment>("POST", `orders/${orderId}/fulfillments.json`, "fulfillment", { fulfillment });
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, ".json"), "fulfillment", { fulfillment });
}

/**
Expand All @@ -26,7 +30,7 @@ export class Fulfillments extends BaseService {
* @param fulfillment The updated fulfillment.
*/
public update(orderId: number, fulfillmentId: number, fulfillment: Fulfillment) {
return this.createRequest<Fulfillment>("PUT", `orders/${orderId}/fulfillments/${fulfillmentId}.json`, "fulfillment", { fulfillment });
return this.createRequest<Fulfillment>("PUT", this.getPath(orderId, ".json"), "fulfillment", { fulfillment });
}

/**
Expand All @@ -35,8 +39,8 @@ export class Fulfillments extends BaseService {
* @param fulfillmentId Id of the fulfillment being retrieved.
* @param options Options for filtering the result.
*/
public get(orderId: number, fulfillmentId: number, options?: Options.FieldOptions) {
return this.createRequest<Fulfillment>("GET", `orders/${orderId}/fulfillments/${fulfillmentId}.json`, "fulfillment", options);
public get(orderId: number, id: number, options?: Options.FieldOptions) {
return this.createRequest<Fulfillment>("GET", this.getPath(orderId, `${id}.json`), "fulfillment", options);
}

/**
Expand All @@ -45,7 +49,7 @@ export class Fulfillments extends BaseService {
* @param options Options for filtering the results.
*/
public list(orderId: number, options?: Options.FulfillmentListOptions) {
return this.createRequest<Fulfillment[]>("GET", `orders/${orderId}/fulfillments.json`, "fulfillments", options);
return this.createRequest<Fulfillment[]>("GET", this.getPath(orderId, ".json"), "fulfillments", options);
}

/**
Expand All @@ -54,33 +58,33 @@ export class Fulfillments extends BaseService {
* @param options Options for filtering the results.
*/
public count(orderId: number, options?: Options.FulfillmentCountOptions) {
return this.createRequest<number>("GET", `orders/${orderId}/fulfillments/count.json`, "count", options);
return this.createRequest<number>("GET", this.getPath(orderId, "count.json"), "count", options);
}

/**
* Opens a fulfillment with the given id.
* @param id The fulfillment's id.
*/
public open(id: number) {
return this.createRequest<Fulfillment>("POST", `${id}/open.json`, 'fulfillment');
public open(orderId: number, id: number) {
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, `${id}/open.json`), 'fulfillment');
}

/**
* Cancels a fulfillment with the given id.
* @param id The fulfillment's id.
* @param options Options for canceling the fulfillment.
*/
public cancel(id: number) {
return this.createRequest<Fulfillment>("POST", `${id}/cancel.json`, 'fulfillment');
public cancel(orderId: number, id: number) {
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, `${id}/cancel.json`), 'fulfillment');
}

/**
* Complete a fulfillment with the given id.
* @param id The fulfillment's id.
* @param options Options for canceling the fulfillment.
*/
public complete(id: number) {
return this.createRequest<Fulfillment>("POST", `${id}/complete.json`, 'fulfillment');
public complete(orderId: number, id: number) {
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, `${id}/complete.json`), 'fulfillment');
}
}

Expand Down
2 changes: 2 additions & 0 deletions services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export * from "./orders";
export * from "./price_rule_discounts";
export * from "./price_rules";
export * from "./products";
export * from "./product_variants";
export * from "./recurring_charges";
export * from "./redirects";
export * from "./script_tags";
export * from "./shops";
export * from "./smart_collections";
export * from "./usage_charges";
export * from "./webhooks";
export * from "./product_variants";
59 changes: 59 additions & 0 deletions services/product_variants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as Options from '../options';
import { ProductVariant } from '../models';
import { BaseService } from '../infrastructure';

/**
* A service for manipulating a blog's product variants.
*/
export class ProductVariants extends BaseService {
constructor(shopDomain: string, accessToken: string) {
super(shopDomain, accessToken, "");
}

/**
* Gets a variant with the given id.
* @param id Id of the variant being retrieved.
* @param options Options for filtering the result.
*/
public get(id: number, options?: Options.FieldOptions) {
return this.createRequest<ProductVariant>("GET", `variants/${id}.json`, "variant", options);
}

/**
* Lists up to 250 variants for the given product.
* @param productId Id of the product that the variants belong to.
* @param options Options for filtering the results.
*/
public list(productId: number, options?: Options.FieldOptions) {
return this.createRequest<ProductVariant>("GET", `products/${productId}/variants.json`, "variants", options);
}

/**
* Counts the variants on the given product.
* @param productId Id of the product that the variants belong to.
* @param options Options for filtering the results.
*/
public count(productId: number, options?: Options.FulfillmentCountOptions) {
return this.createRequest<number>("GET", `products/${productId}/variants/count.json`, "count", options);
}

/**
* Updates an variant with the given id.
* @param id Id of the variant.
* @param productVariant The updated variant.
*/
public update(id: number, variant: ProductVariant) {
return this.createRequest<ProductVariant>("PUT", `variants/${id}.json`, "variant", { variant });
}

/**
* Deletes the variant with the given variantId.
* @param productId Id of the product that the varaint belongs to.
* @param variantId Id of the variant to delete.
*/
public delete(productId: number, variantId: number) {
return this.createRequest<void>("DELETE", `products/${productId}/variants/${variantId}.json`);
}
}

export default ProductVariants;

0 comments on commit 0dce9a8

Please sign in to comment.