177 lines
4.7 KiB
Markdown
177 lines
4.7 KiB
Markdown
# carrier
|
|
|
|
This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`.
|
|
|
|
## `carrier.create`
|
|
|
|
*Source: `src/store/carrier/create.js`*
|
|
|
|
Creates a new carrier for the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `input` | `object` | Carrier input. |
|
|
| `input.name` | `string` | The carrier name. |
|
|
| `[input.sort]` | `number` | Optional sort order (auto-increments if omitted). |
|
|
| `[input.hasPackages=false]` | `boolean` | Whether this carrier uses packages. |
|
|
| `[input.isReverse=false]` | `boolean` | Whether this carrier handles reverse shipments. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{id: number, name: string, sort: number, hasPackages: boolean, isReverse: boolean}>` — The created carrier.
|
|
|
|
**Throws**
|
|
|
|
`Error` — If name is missing, sort is invalid, or carrier already exists.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const c = await store.carrier.create(googleAuthId, { name: 'DHL', hasPackages: true });
|
|
// => { id: 1, name: 'DHL', sort: 0, hasPackages: true, isReverse: false }
|
|
```
|
|
|
|
## `carrier.delete`
|
|
|
|
*Source: `src/store/carrier/delete.js`*
|
|
|
|
Deletes a carrier for the user's selected company, unless referenced in shipping.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `id` | `number` | The carrier ID to delete. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<void>`
|
|
|
|
**Throws**
|
|
|
|
`Error` — If carrier not found or in use in shipping.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
await store.carrier.delete(googleAuthId, 1);
|
|
```
|
|
|
|
## `carrier.getById`
|
|
|
|
*Source: `src/store/carrier/getById.js`*
|
|
|
|
Retrieves a carrier by its ID for the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `id` | `number` | The carrier ID. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{id: number, name: string, sort: number, hasPackages: boolean, isReverse: boolean}|undefined>` — The carrier or undefined.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const c = await store.carrier.getById(googleAuthId, 1);
|
|
// => { id: 1, name: 'DHL', sort: 0, hasPackages: true, isReverse: false }
|
|
```
|
|
|
|
## `carrier.list`
|
|
|
|
*Source: `src/store/carrier/list.js`*
|
|
|
|
Lists all carriers for the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<Array<{id: number, name: string, sort: number, hasPackages: boolean, isReverse: boolean}>>` — List of carriers.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const carriers = await store.carrier.list(googleAuthId);
|
|
// => [{ id: 1, name: 'DHL', sort: 0, hasPackages: true, isReverse: false }]
|
|
```
|
|
|
|
## `carrier.order`
|
|
|
|
*Source: `src/store/carrier/order.js`*
|
|
|
|
Reorders the carriers of the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `input` | `object` | The reorder input. |
|
|
| `input.carrierIds` | `Array<number>` | The carrier ids in their new order. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{carrierIds: Array<number>}>` — The applied order.
|
|
|
|
**Throws**
|
|
|
|
`Error` — If the order is invalid.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
await store.carrier.order(googleAuthId, { carrierIds: [2, 1, 3] });
|
|
```
|
|
|
|
## `carrier.update`
|
|
|
|
*Source: `src/store/carrier/update.js`*
|
|
|
|
Updates a carrier name, sort order, hasPackages, and/or isReverse for the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `id` | `number` | The carrier ID to update. |
|
|
| `input` | `object` | Update payload. |
|
|
| `[input.name]` | `string` | The new carrier name. |
|
|
| `[input.sort]` | `number` | The new sort order. |
|
|
| `[input.hasPackages]` | `boolean` | Whether carrier uses packages. |
|
|
| `[input.isReverse]` | `boolean` | Whether carrier handles reverse shipments. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{id: number, name: string, sort: number, hasPackages: boolean, isReverse: boolean}>` — The updated carrier.
|
|
|
|
**Throws**
|
|
|
|
`Error` — If carrier not found, name is empty, sort is invalid, or carrier already exists.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const updated = await store.carrier.update(googleAuthId, 1, { name: 'DHL Express', hasPackages: true });
|
|
// => { id: 1, name: 'DHL Express', sort: 0, hasPackages: true, isReverse: false }
|
|
```
|