Skip to content

Commit

Permalink
feat: batch endpoints added (#8)
Browse files Browse the repository at this point in the history
* feat: batch endpoints

* chore: implement pr feedback

* test: run batch tests last
  • Loading branch information
UnderKoen authored Feb 19, 2024
1 parent 66d0dcf commit 0099217
Show file tree
Hide file tree
Showing 21 changed files with 1,573 additions and 159 deletions.
164 changes: 164 additions & 0 deletions docs/Batch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
Contains all information about a given Batch

# Fields

| Name | Type | Description |
| ---------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id` | `string` | The ID of the batch. |
| `companyId` | `string` | The ID of the company the batch belongs to. |
| `Name` | `string` | The name of the batch. |
| `billingId` | `string` \| `undefined` | The ID assigned to the batch by the customer. |
| `finish` | `string` | The finish of the batch. Can be `GLOSSY` or `MATT`. |
| `isBillable` | `boolean` | Whether the batch is billable. True when an live API key is used, false when a test API key is used. |
| `templateId` | `string` | The ID of the template the batch is based on. |
| `estimatedPrice` | `number` | The estimated price of the batch. |
| `status` | `string` | The status of the batch. Can be `batch_created`, `batch_needs_approval`, `batch_user_ready`, `batch_ready_to_schedule`, `batch_scheduling`, `batch_scheduled` or `batch_sent` |
| `orders` | `object` | An object containing the orders of the batch. With keys 'processing', 'success', 'failed' and 'cancelled' |
| `createdAt` | `string` | The date the batch was created. |
| `updatedAt` | `string` | The date the batch was last updated. |

# Methods

## `.getTemplate()`

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

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

**Example**

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

---

## `.refresh()`

Refresh the batch data to get the latest information

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

**Example**

```js
const batch: Batch;
await batch.refresh();
```

---

## [`.getOrders([options])`](./PrintOne#getordersoptions)

Get all orders in the batch.

**Parameters**

| Name | Type | Default | Description |
| ------------------------------- | ----------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `options.limit` | `number` | `10` | The maximum number of batchs to return. |
| `options.page` | `number` | `1` | The page of batchs to return. |
| `options.sortBy` | [`sort`](./Filtering#Sorting) | `createdAt:DESC` | The field(s) to sort the batchs by. Can be `createdAt`, `anonymizedAt`, `updatedAt`, `friendlyStatus` or `sendDate` |
| `options.filter.friendlyStatus` | `string` \| `string[]` | `undefined` | The friendly status(es) of the batch(s) to filter by. Can be `Processing`, `Success`, `Sent`, `Scheduled`, `Cancelled` or `Failed` |
| `options.filter.billingId` | `string` \| `string[]` | `undefined` | The billing ID(s) of the batch(s) to filter by. |
| `options.filter.format` | `string` \| `string[]` | `undefined` | The format(s) of the batch(s) to filter by. Can be `POSTCARD_A5`, `POSTCARD_A6`, `POSTCARD_SQ14` or `GREETINGCARD_SQ15` |
| `options.filter.finish` | `string` \| `string[]` | `undefined` | The finish(es) of the batch(s) to filter by. Can be `GLOSSY` or `MATTE` |
| `options.filter.isBillable` | `boolean` | `undefined` | Whether the batch(s) are live batch or test batchs. |
| `options.filter.createdAt` | [`date`](./Filtering#Date) | `undefined` | The date(s) the batch(s) were created on. |

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

**Example**

```js
const orders = await batch.getOrders({
limit: 20,
page: 1,
sortBy: "createdAt:ASC",
filter: {
friendlyStatus: "Success",
format: Format.POSTCARD_A5,
finish: Finish.GLOSSY,
isBillable: true,
createdAt: {
from: "2020-01-01",
to: "2020-01-31",
},
},
});
```

---

## [`.getOrder(orderId)`](./PrintOne#getorderorderid)

Get a specific order in the batch.

**Parameters**

| Name | Type | Description |
| --------- | -------- | -------------------- |
| `orderId` | `string` | The ID of the order. |

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

**Example**

```js
const order = await batch.getOrder("example-order-id");
```

---

## `.createOrder(data)`

Create a new order in the batch.

**Parameters**

| Name | Type | Description |
| ---------------- | ---------------------------- | --------------------------------- |
| `data.recipient` | [`Address`](./Order#Address) | The recipient of the order. |
| `mergeVariables` | `object` | The merge variables of the order. |

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

**Example**

```js
const order = await batch.createOrder({
recipient: {
name: "John Doe",
address: "123 Main St",
city: "Anytown",
postalCode: "1221AH",
country: "Nederland",
},
mergeVariables: {
name: "John Doe",
},
});
```

---

## `.update(data)`

Update the batch.

**Parameters**

| Name | Type | Description |
| ------------ | ------------------- | ------------------------------------------- |
| `data.ready` | `Date` \| `boolean` | Whether the batch is ready to be scheduled. |

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

**Example**

```js
await batch.update({
ready: true,
});
```
42 changes: 21 additions & 21 deletions docs/CsvOrder.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ Contains all information about a given CsvOrder

# Fields

| Name | Type | Description |
| --------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id` | `string` | The ID of the order. |
| `templateId` | `string` | The ID of the template the order is based on. |
| `finish` | `string` | The finish of the order. Can be `GLOSSY` or `MATT`. |
| `format` | `string` | The format of the order. Can be `POSTCARD_A5`, `POSTCARD_A6`, `POSTCARD_SQ14` or `GREETINGCARD_SQ15`. |
| `mergeVariableMapping` | `object` | The merge variables of the order. Keys are the merge variable names. |
| `sender` | [`Address`](#Address) \| `undefined` | The sender of the order. |
| `recipientMapping` | [`Address`](#Address) | The mapping of the recipient. |
| `definitiveCountryId` | `string` | The ID of the definitive country of the order. |
| `billingId` | `string` \| `undefined` | The ID assigned to the csv order by the customer. |
| `isBillable` | `boolean` | Whether the csv order is billable. True when an live API key is used, false when a test API key is used. |
| `status` | `string` | The status of the csv order. Can be `order_created` or `order_processed` |
| `friendlyStatus` | `string` | The friendly status of the csv order. Can be `Processing` or `Success` |
| `estimatedOrderCount` | `number` | The amount of initial orders in the CSV
| `failedOrderCount` | `number` | The amount of orders which have failed to be processed
| `processedOrderCount` | `number` | The amount of orders which have successfully been processed
| `totalOrderCount` | `number` | The total amount of orders failed or processed
| `sendDate` | `Date` | The date the order will be sent on. |
| `createdAt` | `Date` | The date and time the order was created. |
| `updatedAt` | `Date` | The date and time the order was last updated. |
| Name | Type | Description |
| ---------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------- |
| `id` | `string` | The ID of the order. |
| `templateId` | `string` | The ID of the template the order is based on. |
| `finish` | `string` | The finish of the order. Can be `GLOSSY` or `MATT`. |
| `format` | `string` | The format of the order. Can be `POSTCARD_A5`, `POSTCARD_A6`, `POSTCARD_SQ14` or `GREETINGCARD_SQ15`. |
| `mergeVariableMapping` | `object` | The merge variables of the order. Keys are the merge variable names. |
| `sender` | [`Address`](#Address) \| `undefined` | The sender of the order. |
| `recipientMapping` | [`Address`](#Address) | The mapping of the recipient. |
| `definitiveCountryId` | `string` | The ID of the definitive country of the order. |
| `billingId` | `string` \| `undefined` | The ID assigned to the csv order by the customer. |
| `isBillable` | `boolean` | Whether the csv order is billable. True when an live API key is used, false when a test API key is used. |
| `status` | `string` | The status of the csv order. Can be `order_created` or `order_processed` |
| `friendlyStatus` | `string` | The friendly status of the csv order. Can be `Processing` or `Success` |
| `estimatedOrderCount` | `number` | The amount of initial orders in the CSV |
| `failedOrderCount` | `number` | The amount of orders which have failed to be processed |
| `processedOrderCount` | `number` | The amount of orders which have successfully been processed |
| `totalOrderCount` | `number` | The total amount of orders failed or processed |
| `sendDate` | `Date` | The date the order will be sent on. |
| `createdAt` | `Date` | The date and time the order was created. |
| `updatedAt` | `Date` | The date and time the order was last updated. |

# Methods

Expand Down
Loading

0 comments on commit 0099217

Please sign in to comment.