102 lines
3.2 KiB
Markdown
102 lines
3.2 KiB
Markdown
# shipping
|
|
|
|
This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`.
|
|
|
|
## `shipping.create`
|
|
|
|
*Source: `src/store/shipping/create.js`*
|
|
|
|
Creates a shipping (package) for a shipment manifest. The number is allocated from the `shipping` numbers sequence (own prefix + counter). If state is 'shipped', adjusts stock by appending negative ledger movements for tracked shipment lines, writes article history for all items, and ensures stock is deducted once.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `input` | `object` | Shipping input. |
|
|
| `input.manifestId` | `number` | The shipment manifest id. |
|
|
| `input.carrierId` | `number` | The carrier id. |
|
|
| `input.type` | `string` | Shipping type. |
|
|
| `input.state` | `string` | Shipping state ('shipped' or other). |
|
|
| `[input.trackingCode]` | `string` | Carrier tracking code. |
|
|
| `[input.warehouseId]` | `number` | Optional warehouse ID for stock deduction (defaults to company's first warehouse). |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<{id: number, manifestId: number, number: string, trackingCode: string|null, carrierId: number, carrier: string|null, type: string, state: string}>`
|
|
|
|
**Throws**
|
|
|
|
`Error` — If manifest is not found, carrier is not found, manifest is not a shipment, or input is invalid.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
await store.shipping.create(googleAuthId, { manifestId: 42, carrierId: 1, type: 'parcel', state: 'shipped', trackingCode: '1Z999' });
|
|
```
|
|
|
|
## `shipping.delete`
|
|
|
|
*Source: `src/store/shipping/delete.js`*
|
|
|
|
Deletes a shipping of the user's selected company. Its packages are removed by cascade. Once shipped, a shipping cannot be deleted because stock movements have been ledgered.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `id` | `number` | The shipping id. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<void>`
|
|
|
|
**Throws**
|
|
|
|
`Error` — If shipping is not found or is already shipped.
|
|
|
|
**Example**
|
|
|
|
```js
|
|
await store.shipping.delete(googleAuthId, 9);
|
|
```
|
|
|
|
## `shipping.listByManifestId`
|
|
|
|
*Source: `src/store/shipping/listByManifestId.js`*
|
|
|
|
Lists shippings of a manifest (order) in the user's selected company.
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
|
| `manifestId` | `number` | The manifest id. |
|
|
| `[tx]` | `object` | Optional transaction to run within. |
|
|
|
|
**Returns**
|
|
|
|
`Promise<Array<{id: number, manifestId: number, number: string, type: string, state: string}>>`
|
|
|
|
**Example**
|
|
|
|
```js
|
|
const shippings = await store.shipping.listByManifestId(googleAuthId, 42);
|
|
```
|
|
|
|
## `shipping.update`
|
|
|
|
*Source: `src/store/shipping/update.js`*
|
|
|
|
Updates a shipping record for the user's selected company. If transitioned to 'shipped', books ledger movements and adjusts stock. Once shipped, shipping cannot be undone (state cannot be changed away from 'shipped').
|
|
|
|
**Parameters**
|
|
|
|
| Name | Type | Description |
|
|
| --- | --- | --- |
|
|
| `provider` | `import('../../providers/provider.js').DatabaseProvider` | |
|