Skip to content

Commit

Permalink
docs: 📝 added docs for coupons
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRill00 committed Jul 25, 2024
1 parent c3c3234 commit 885836e
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 0 deletions.
111 changes: 111 additions & 0 deletions docs/Coupon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
Contains all information about a given CsvOrder

# Fields

| Name | Type | Description |
| ---------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------- |
| `id` | `string` | The ID of the coupon. |
| `name` | `string` | The name of the coupon. |
| `companyId` | `string` | The ID of the company the coupon belongs to. |
| `stats` | `object` | An object containing the stats of the coupon. With keys 'total', 'used' and 'remaining' |

# Methods

## `.getTemplate()`

Get the template the order is based on. Uses [`PrintOne.getTemplate()`](./PrintOne#gettemplateid).

**Returns: [`Promise<Template>`](./Template)**

**Example**

```js
const order = await client.getOrder("example-order-id");
const template = await order.getTemplate();
```

---

## `.refresh()`

Refresh the Coupon data to get the latest information

**Returns: `Promise<void>`**

**Example**

```js
const coupon: Coupon;
await coupon.refresh();
```

---

## `Coupon.getCodes()`

Get all coupon codes within the coupon. |

**Returns: [`Promise<PaginatedResponse<CouponCode>>`](./CouponCode)**

**Example**

```js
const couponCodes = await coupon.getCodes();
```

---

## `Coupon.getCode(id)`

Get all coupon codes by its ID.

**Parameters**

| Name | Type | Description |
| ---- | -------- | --------------------------------- |
| `id` | `string` | The ID of the coupon code to get. |

**Returns: [`Promise<PaginatedResponse<CouponCode>>`](./CouponCode)**

**Example**

```js
const couponCode = await coupon.getCode('example-coupon-code-id');
```

---

## `Coupon.addCodes(csv)`

Add coupon codes to the coupon by uploading a CSV.

**Parameters**

| Name | Type | Description |
| ---------- | ------------- | --------------------------------- |
| `csv` | `ArrayBuffer` | The file to upload. Must be a CSV |

**Returns: `Promise<void>`

**Example**

```js
const data = fs.readFileSync("example.csv").buffer;
const file = await coupon.addCodes(data);
```


---

## `Coupon.delete()`

Delete the coupon.

**Returns: `Promise<void>`

**Example**

```js
await coupon.delete();
```

43 changes: 43 additions & 0 deletions docs/CouponCode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Contains all information about a given CsvOrder

# Fields

| Name | Type | Description |
| ---------------------- | ------------------------------------ | --------------------------------------------------------------------------------- |
| `id` | `string` | The ID of the coupon code. |
| `couponId` | `string` | The ID of the parent coupon. |
| `code` | `string` | The actual code saved for the coupon code`. |
| `used` | `boolean` | Whether the coupon code has been used. |
| `usedAt` | `Date` or `null` | The date at which the coupon code was used or `null` if not used yet. |
| `orderId` | `string` or `null` | The order ID by which the coupon code was used or `null` if not used yet. |

# Methods
---

## `.refresh()`

Refresh the CouponCode data to get the latest information

**Returns: `Promise<void>`**

**Example**

```js
const couponCode: CouponCOde;
await couponCode.refresh();
```

---

## `.getOrder()`

Get the order the coupon code was used by. You might need to do [`CouponCode.refresh`](#refresh) first when coupon was used after fetching.

**Returns: [`Promise<Order|null>`](./Order)**

**Example**

```js
const couponCode: CouponCode
const order = await couponCode.getOrder();;
```
74 changes: 74 additions & 0 deletions docs/PrintOne.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,77 @@ const csvOrder = await client.getCsvOrder("example-order-id");
```
```

--

## `.createCoupon(data)`

Create a new coupon.

**Parameters**

| Name | Type | Description |
| ------ | -------- | ------------------------------------------------------------------------------------------- |
| `data` | `object` | The data to create the coupon with. See [`Order`](./Coupon#createcoupondata) for more info. |

**Returns: [`Promise<Coupon>`](./Order)**

**Example**

```js
const coupon = await client.createCoupon({
name: "coupon",
});
```

---

## `.getCoupons([options])`

Get all coupons.

**Parameters**

| Name | Type | Default | Description |
| ------------------------------- | ----------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `options.limit` | `number` | `10` | The maximum number of coupons to return. |
| `options.page` | `number` | `1` | The page of coupons to return. |
| `options.sortBy` | [`sort`](./Filtering#Sorting) | `createdAt:DESC` | The field(s) to sort the coupons by. Can be `createdAt` or `name` |
| `options.filter.name` | `string` \| `string[]` | `undefined` | The name(s) of the coupon(s) to filter |

**Returns: [`Promise<PaginatedResponse<Order>>`](./Order)**

**Example**

```js
const coupons = await client.getCoupons({
limit: 20,
page: 1,
sortBy: "createdAt:ASC",
filter: {
name: "test",
},
});
```

---

## `.getCoupon(id)`

Get a coupon by its ID.

**Parameters**

| Name | Type | Description |
| ---- | -------- | ---------------------------- |
| `id` | `string` | The ID of the coupon to get. |

**Returns: [`Promise<Coupon>`](./Coupon)**

**Example**

```js
const coupon = await client.getCoupon("example-coupon-id");
```

---

0 comments on commit 885836e

Please sign in to comment.