@newpeak/barista-cli 0.1.6 ā 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +714 -0
- package/README.ja.md +708 -0
- package/README.md +68 -0
- package/README.vi.md +714 -0
- package/dist/commands/liberica/index.d.ts.map +1 -1
- package/dist/commands/liberica/index.js +4 -0
- package/dist/commands/liberica/index.js.map +1 -1
- package/dist/commands/liberica/materials/create.d.ts.map +1 -1
- package/dist/commands/liberica/materials/create.js +35 -9
- package/dist/commands/liberica/materials/create.js.map +1 -1
- package/dist/commands/liberica/orgs/index.d.ts.map +1 -1
- package/dist/commands/liberica/orgs/index.js.map +1 -1
- package/dist/commands/liberica/users/create.d.ts.map +1 -1
- package/dist/commands/liberica/users/create.js +1 -0
- package/dist/commands/liberica/users/create.js.map +1 -1
- package/dist/commands/liberica/warehouses/create.d.ts +3 -0
- package/dist/commands/liberica/warehouses/create.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/create.js +196 -0
- package/dist/commands/liberica/warehouses/create.js.map +1 -0
- package/dist/commands/liberica/warehouses/delete.d.ts +3 -0
- package/dist/commands/liberica/warehouses/delete.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/delete.js +111 -0
- package/dist/commands/liberica/warehouses/delete.js.map +1 -0
- package/dist/commands/liberica/warehouses/disable.d.ts +3 -0
- package/dist/commands/liberica/warehouses/disable.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/disable.js +173 -0
- package/dist/commands/liberica/warehouses/disable.js.map +1 -0
- package/dist/commands/liberica/warehouses/enable.d.ts +3 -0
- package/dist/commands/liberica/warehouses/enable.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/enable.js +173 -0
- package/dist/commands/liberica/warehouses/enable.js.map +1 -0
- package/dist/commands/liberica/warehouses/get.d.ts +3 -0
- package/dist/commands/liberica/warehouses/get.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/get.js +90 -0
- package/dist/commands/liberica/warehouses/get.js.map +1 -0
- package/dist/commands/liberica/warehouses/index.d.ts +3 -0
- package/dist/commands/liberica/warehouses/index.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/index.js +23 -0
- package/dist/commands/liberica/warehouses/index.js.map +1 -0
- package/dist/commands/liberica/warehouses/list.d.ts +3 -0
- package/dist/commands/liberica/warehouses/list.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/list.js +101 -0
- package/dist/commands/liberica/warehouses/list.js.map +1 -0
- package/dist/commands/liberica/warehouses/locations/create.d.ts +3 -0
- package/dist/commands/liberica/warehouses/locations/create.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/locations/create.js +199 -0
- package/dist/commands/liberica/warehouses/locations/create.js.map +1 -0
- package/dist/commands/liberica/warehouses/locations/delete.d.ts +3 -0
- package/dist/commands/liberica/warehouses/locations/delete.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/locations/delete.js +115 -0
- package/dist/commands/liberica/warehouses/locations/delete.js.map +1 -0
- package/dist/commands/liberica/warehouses/locations/disable.d.ts +3 -0
- package/dist/commands/liberica/warehouses/locations/disable.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/locations/disable.js +173 -0
- package/dist/commands/liberica/warehouses/locations/disable.js.map +1 -0
- package/dist/commands/liberica/warehouses/locations/enable.d.ts +3 -0
- package/dist/commands/liberica/warehouses/locations/enable.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/locations/enable.js +173 -0
- package/dist/commands/liberica/warehouses/locations/enable.js.map +1 -0
- package/dist/commands/liberica/warehouses/locations/get.d.ts +3 -0
- package/dist/commands/liberica/warehouses/locations/get.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/locations/get.js +73 -0
- package/dist/commands/liberica/warehouses/locations/get.js.map +1 -0
- package/dist/commands/liberica/warehouses/locations/index.d.ts +3 -0
- package/dist/commands/liberica/warehouses/locations/index.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/locations/index.js +21 -0
- package/dist/commands/liberica/warehouses/locations/index.js.map +1 -0
- package/dist/commands/liberica/warehouses/locations/list.d.ts +3 -0
- package/dist/commands/liberica/warehouses/locations/list.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/locations/list.js +104 -0
- package/dist/commands/liberica/warehouses/locations/list.js.map +1 -0
- package/dist/commands/liberica/warehouses/locations/update.d.ts +3 -0
- package/dist/commands/liberica/warehouses/locations/update.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/locations/update.js +128 -0
- package/dist/commands/liberica/warehouses/locations/update.js.map +1 -0
- package/dist/commands/liberica/warehouses/update.d.ts +3 -0
- package/dist/commands/liberica/warehouses/update.d.ts.map +1 -0
- package/dist/commands/liberica/warehouses/update.js +143 -0
- package/dist/commands/liberica/warehouses/update.js.map +1 -0
- package/dist/core/api/client.d.ts +16 -0
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +286 -0
- package/dist/core/api/client.js.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/location.d.ts +53 -0
- package/dist/types/location.d.ts.map +1 -0
- package/dist/types/location.js +2 -0
- package/dist/types/location.js.map +1 -0
- package/dist/types/warehouse.d.ts +68 -0
- package/dist/types/warehouse.d.ts.map +1 -0
- package/dist/types/warehouse.js +2 -0
- package/dist/types/warehouse.js.map +1 -0
- package/docs/commands/liberica/locations/create.md +195 -0
- package/docs/commands/liberica/locations/list.md +171 -0
- package/docs/commands/liberica/warehouses/create.md +222 -0
- package/docs/commands/liberica/warehouses/list.md +184 -0
- package/package.json +1 -1
- package/src/commands/liberica/index.ts +4 -0
- package/src/commands/liberica/materials/create.ts +32 -9
- package/src/commands/liberica/orgs/index.ts +0 -1
- package/src/commands/liberica/users/create.ts +1 -0
- package/src/commands/liberica/warehouses/create.ts +204 -0
- package/src/commands/liberica/warehouses/delete.ts +112 -0
- package/src/commands/liberica/warehouses/disable.ts +174 -0
- package/src/commands/liberica/warehouses/enable.ts +174 -0
- package/src/commands/liberica/warehouses/get.ts +101 -0
- package/src/commands/liberica/warehouses/index.ts +25 -0
- package/src/commands/liberica/warehouses/list.ts +136 -0
- package/src/commands/liberica/warehouses/locations/create.ts +209 -0
- package/src/commands/liberica/warehouses/locations/delete.ts +116 -0
- package/src/commands/liberica/warehouses/locations/disable.ts +174 -0
- package/src/commands/liberica/warehouses/locations/enable.ts +174 -0
- package/src/commands/liberica/warehouses/locations/get.ts +84 -0
- package/src/commands/liberica/warehouses/locations/index.ts +23 -0
- package/src/commands/liberica/warehouses/locations/list.ts +140 -0
- package/src/commands/liberica/warehouses/locations/update.ts +135 -0
- package/src/commands/liberica/warehouses/update.ts +142 -0
- package/src/core/api/client.ts +396 -0
- package/src/index.ts +1 -3
- package/src/types/index.ts +4 -4
- package/src/types/location.ts +66 -0
- package/src/types/warehouse.ts +82 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# barista liberica warehouses list
|
|
2
|
+
|
|
3
|
+
List warehouses with pagination.
|
|
4
|
+
|
|
5
|
+
## 2.1 Command Metadata
|
|
6
|
+
|
|
7
|
+
| Field | Value |
|
|
8
|
+
|------|-----|
|
|
9
|
+
| Full Command | `barista liberica warehouses list` |
|
|
10
|
+
| Description | List warehouses with pagination |
|
|
11
|
+
| HTTP Method | GET |
|
|
12
|
+
| Requires Authentication | Yes |
|
|
13
|
+
| Supports Dry-Run | No |
|
|
14
|
+
|
|
15
|
+
## 2.2 Backend API Reference
|
|
16
|
+
|
|
17
|
+
### Controller Location
|
|
18
|
+
```
|
|
19
|
+
coffee-liberica-end/
|
|
20
|
+
āāā facade/liberica-facade-enterprise/
|
|
21
|
+
āāā src/main/java/com/newpeak/liberica/facade/enterprise/controller/stock/
|
|
22
|
+
āāā EnterpriseWarehouseController.java
|
|
23
|
+
āāā page(@GetResource(path = "/page"))
|
|
24
|
+
āāā public ResponseData<PageResult<MasterWarehouseResponse>> page(
|
|
25
|
+
@RequestHeader("X-TENANT-ID") Long tenantId,
|
|
26
|
+
@ParameterObject MasterWarehouseRequest masterWarehouseRequest
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Request DTO Location
|
|
31
|
+
```
|
|
32
|
+
coffee-liberica-end/
|
|
33
|
+
āāā business/liberica-business-master/master-api/
|
|
34
|
+
āāā src/main/java/com/newpeak/liberica/master/api/pojo/request/
|
|
35
|
+
āāā MasterWarehouseRequest.java
|
|
36
|
+
āāā warehouseCode: String
|
|
37
|
+
āāā warehouseName: String
|
|
38
|
+
āāā warehouseClasses: String
|
|
39
|
+
āāā manager: String
|
|
40
|
+
āāā warehouseTelephone: String
|
|
41
|
+
āāā warehouseFax: String
|
|
42
|
+
āāā warehouseAddress: String
|
|
43
|
+
āāā enableLocation: String (Y/N)
|
|
44
|
+
āāā enableNegativeInventory: String (Y/N)
|
|
45
|
+
āāā statusFlag: Integer
|
|
46
|
+
āāā remark: String
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Response DTO Location
|
|
50
|
+
```
|
|
51
|
+
coffee-liberica-end/
|
|
52
|
+
āāā business/liberica-business-master/master-api/
|
|
53
|
+
āāā src/main/java/com/newpeak/liberica/master/api/pojo/response/
|
|
54
|
+
āāā MasterWarehouseResponse.java
|
|
55
|
+
āāā warehouseId: Long
|
|
56
|
+
āāā warehouseCode: String
|
|
57
|
+
āāā warehouseName: String
|
|
58
|
+
āāā warehouseClasses: String
|
|
59
|
+
āāā manager: String
|
|
60
|
+
āāā warehouseTelephone: String
|
|
61
|
+
āāā warehouseFax: String
|
|
62
|
+
āāā warehouseAddress: String
|
|
63
|
+
āāā enableLocation: String (Y/N)
|
|
64
|
+
āāā enableNegativeInventory: String (Y/N)
|
|
65
|
+
āāā statusFlag: Integer (1=enable, 2=disable)
|
|
66
|
+
āāā remark: String
|
|
67
|
+
āāā locations: List<MasterWarehouseLocationResponse>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 2.3 CLI Parameter Design
|
|
71
|
+
|
|
72
|
+
### Command Structure
|
|
73
|
+
```
|
|
74
|
+
barista liberica warehouses list [options]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Global Options
|
|
78
|
+
| Option | Type | Description |
|
|
79
|
+
|------|------|------|
|
|
80
|
+
| `--env` | string | Target environment (dev\|test\|prod-cn\|prod-jp) |
|
|
81
|
+
| `--tenant` | string | Tenant code |
|
|
82
|
+
| `--json` | boolean | JSON output |
|
|
83
|
+
|
|
84
|
+
### Command Options
|
|
85
|
+
| Option | Short | Type | Required | Default | Description | Maps to Query Param |
|
|
86
|
+
|------|--------|------|------|--------|------|-------------|
|
|
87
|
+
| --page | -p | number | No | 1 | Page number (CLI 1-based) | pageNo (0-based) |
|
|
88
|
+
| --size | -s | number | No | 20 | Page size | pageSize |
|
|
89
|
+
| --status | ā | number | No | - | Status filter (1=enable, 2=disable) | statusFlag |
|
|
90
|
+
| --keyword | -k | string | No | - | Keyword search (warehouseName and warehouseCode) | warehouseName / warehouseCode |
|
|
91
|
+
| --classes | ā | string | No | - | Warehouse class filter | warehouseClasses |
|
|
92
|
+
| --enable-location | ā | boolean | No | - | Filter by location management enabled | enableLocation |
|
|
93
|
+
|
|
94
|
+
## 2.4 Field Mapping Table
|
|
95
|
+
|
|
96
|
+
| CLI Parameter | Query Param / DTO Field | Type Conversion | Validation Rule |
|
|
97
|
+
|---------|---------|----------|----------|
|
|
98
|
+
| --page / -p | pageNo | number, CLI page - 1 | >= 0 |
|
|
99
|
+
| --size / -s | pageSize | number | > 0 |
|
|
100
|
+
| --status | statusFlag | number | 1 or 2 |
|
|
101
|
+
| --keyword / -k | warehouseName / warehouseCode | Direct | max=255 |
|
|
102
|
+
| --classes | warehouseClasses | Direct | max=255 |
|
|
103
|
+
| --enable-location | enableLocation | boolean->String (Y/N) | max=1 |
|
|
104
|
+
|
|
105
|
+
## 2.5 Error Code Reference
|
|
106
|
+
|
|
107
|
+
### ExceptionEnum Location
|
|
108
|
+
```
|
|
109
|
+
coffee-liberica-end/
|
|
110
|
+
āāā business/liberica-business-master/master-api/
|
|
111
|
+
āāā src/main/java/com/newpeak/liberica/master/api/exception/enums/
|
|
112
|
+
āāā MasterWarehouseExceptionEnum.java
|
|
113
|
+
āāā MASTER_WAREHOUSE_NOT_EXIST("01001370001", "ē§ę·ä»åŗäøååØ")
|
|
114
|
+
āāā MASTER_WAREHOUSE_CODE_FORMAT_CANNOT_EMPTY("01001370002", "ä»åŗē¼ē č§åäøč½äøŗē©ŗ")
|
|
115
|
+
āāā MASTER_WAREHOUSE_CODE_FORMAT_NOT_CORRECT("01001370003", "ä»åŗē¼ē č§åę ¼å¼äøę£ē”®")
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Known Error Codes
|
|
119
|
+
| Error Code | Error Message | Trigger Condition |
|
|
120
|
+
|--------|----------|----------|
|
|
121
|
+
| 01001370001 | Warehouse does not exist | Detail query with non-existent ID |
|
|
122
|
+
|
|
123
|
+
## 2.6 Permission Check
|
|
124
|
+
|
|
125
|
+
| Check Item | Location | Description |
|
|
126
|
+
|--------|------|------|
|
|
127
|
+
| Page Query | No specific permission code on `@GetResource(path = "/page")` | Available to authenticated users |
|
|
128
|
+
|
|
129
|
+
## 2.7 Implementation Notes
|
|
130
|
+
|
|
131
|
+
1. **Pagination**: CLI uses 1-based page numbers. API uses 0-based. Convert: `pageNo = options.page - 1`.
|
|
132
|
+
2. **Response Fields**: Backend returns `rows`, `pageNo`, `pageSize`, `totalRows`. Do NOT use `records` or `total`.
|
|
133
|
+
3. **Keyword Search**: When `--keyword` is provided, send it as both `warehouseName` and `warehouseCode` query params.
|
|
134
|
+
4. **BigInteger ID**: `warehouseId` in response rows must be kept as `string` in TypeScript.
|
|
135
|
+
5. **Table Output**: Default columns: ID, Code, Name, Classes, Location, Status.
|
|
136
|
+
6. **JSON Output**: When `--json` is used, wrap response with standardized pagination object.
|
|
137
|
+
|
|
138
|
+
## 2.8 Example Usage
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# List all warehouses (first page, 20 per page)
|
|
142
|
+
barista liberica warehouses list
|
|
143
|
+
|
|
144
|
+
# List with pagination
|
|
145
|
+
barista liberica warehouses list --page 2 --size 50
|
|
146
|
+
|
|
147
|
+
# Filter by status
|
|
148
|
+
barista liberica warehouses list --status 1
|
|
149
|
+
|
|
150
|
+
# Keyword search
|
|
151
|
+
barista liberica warehouses list --keyword "Main"
|
|
152
|
+
|
|
153
|
+
# Filter by class
|
|
154
|
+
barista liberica warehouses list --classes "FINISHED_GOOD"
|
|
155
|
+
|
|
156
|
+
# JSON output
|
|
157
|
+
barista liberica warehouses list --json
|
|
158
|
+
|
|
159
|
+
# Combine filters
|
|
160
|
+
barista liberica warehouses list \
|
|
161
|
+
--page 1 \
|
|
162
|
+
--size 10 \
|
|
163
|
+
--status 1 \
|
|
164
|
+
--keyword "WH-001" \
|
|
165
|
+
--json
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## 2.9 API Path
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
GET /api/enterprise/purchases/warehouse/page
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Query Parameters:**
|
|
175
|
+
```
|
|
176
|
+
?pageNo=0&pageSize=20&statusFlag=1&warehouseCode=Main&warehouseName=Main
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Headers:**
|
|
180
|
+
```
|
|
181
|
+
Authorization: <token> (No "Bearer " prefix)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Note**: Do NOT include `X-TENANT-ID` header. Tenant is extracted from JWT token.
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import { createSuppliersCommand } from './suppliers/index.js';
|
|
|
12
12
|
import { createMaterialsCommand } from './materials/index.js';
|
|
13
13
|
import { createUomsCommand } from './uoms/index.js';
|
|
14
14
|
import { createCurrencyCommand } from './currency/index.js';
|
|
15
|
+
import { createWarehousesCommand } from './warehouses/index.js';
|
|
15
16
|
|
|
16
17
|
export function createLibericaCommand(): Command {
|
|
17
18
|
const libericaCommand = new Command('liberica');
|
|
@@ -29,6 +30,7 @@ export function createLibericaCommand(): Command {
|
|
|
29
30
|
libericaCommand.addCommand(createMaterialsCommand());
|
|
30
31
|
libericaCommand.addCommand(createUomsCommand());
|
|
31
32
|
libericaCommand.addCommand(createCurrencyCommand());
|
|
33
|
+
libericaCommand.addCommand(createWarehousesCommand());
|
|
32
34
|
|
|
33
35
|
libericaCommand.action(() => {
|
|
34
36
|
console.log(chalk.bold('\nā Liberica Commands\n'));
|
|
@@ -43,6 +45,8 @@ export function createLibericaCommand(): Command {
|
|
|
43
45
|
console.log(' Use "barista liberica materials <command>" for material management');
|
|
44
46
|
console.log(' Use "barista liberica uoms <command>" for unit of measure management');
|
|
45
47
|
console.log(' Use "barista liberica currencies <command>" for currency management');
|
|
48
|
+
console.log(' Use "barista liberica warehouses <command>" for warehouse management');
|
|
49
|
+
console.log(' Use "barista liberica warehouses locations <command>" for warehouse location management');
|
|
46
50
|
console.log('\n Run "barista liberica <command> --help" for more details\n');
|
|
47
51
|
});
|
|
48
52
|
|
|
@@ -29,19 +29,26 @@ export function createMaterialsCreateCommand(): Command {
|
|
|
29
29
|
.option('--dry-run', 'Preview without making API call')
|
|
30
30
|
.option('--json', 'Output as JSON');
|
|
31
31
|
|
|
32
|
-
cmd.action(async () => {
|
|
32
|
+
cmd.action(async (options) => {
|
|
33
33
|
const context = configManager.getCurrentContext();
|
|
34
|
-
const opts = cmd.opts();
|
|
35
34
|
|
|
36
|
-
let name =
|
|
37
|
-
let materialNo = (
|
|
38
|
-
let materialClass =
|
|
39
|
-
const materialType =
|
|
40
|
-
const materialUnit =
|
|
41
|
-
const dryRun =
|
|
42
|
-
const outputJson =
|
|
35
|
+
let name = options.name as string | undefined;
|
|
36
|
+
let materialNo = (options.no as string | undefined) || (options['no'] as string | undefined);
|
|
37
|
+
let materialClass = options.class as string | undefined;
|
|
38
|
+
const materialType = options.type as string | undefined;
|
|
39
|
+
const materialUnit = options.unit as string | undefined;
|
|
40
|
+
const dryRun = options.dryRun === true;
|
|
41
|
+
const outputJson = options.json === true;
|
|
43
42
|
|
|
44
43
|
if (!name) {
|
|
44
|
+
if (dryRun) {
|
|
45
|
+
if (outputJson) {
|
|
46
|
+
console.log(JSON.stringify({ success: false, error: { code: 'DRY_RUN_MISSING_ARGS', message: 'Missing required --name in dry-run mode' } }));
|
|
47
|
+
} else {
|
|
48
|
+
console.error(chalk.red('\nā --name is required. Cannot preview without material name.\n'));
|
|
49
|
+
}
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
45
52
|
const { inputName } = await inquirer.prompt([
|
|
46
53
|
{
|
|
47
54
|
type: 'input',
|
|
@@ -54,6 +61,14 @@ export function createMaterialsCreateCommand(): Command {
|
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
if (!materialClass) {
|
|
64
|
+
if (dryRun) {
|
|
65
|
+
if (outputJson) {
|
|
66
|
+
console.log(JSON.stringify({ success: false, error: { code: 'DRY_RUN_MISSING_ARGS', message: 'Missing required --class in dry-run mode' } }));
|
|
67
|
+
} else {
|
|
68
|
+
console.error(chalk.red('\nā --class is required. Cannot preview without material class.\n'));
|
|
69
|
+
}
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
57
72
|
const { inputClass } = await inquirer.prompt([
|
|
58
73
|
{
|
|
59
74
|
type: 'input',
|
|
@@ -66,6 +81,14 @@ export function createMaterialsCreateCommand(): Command {
|
|
|
66
81
|
}
|
|
67
82
|
|
|
68
83
|
if (!materialNo) {
|
|
84
|
+
if (dryRun) {
|
|
85
|
+
if (outputJson) {
|
|
86
|
+
console.log(JSON.stringify({ success: false, error: { code: 'DRY_RUN_MISSING_ARGS', message: 'Missing required --no in dry-run mode' } }));
|
|
87
|
+
} else {
|
|
88
|
+
console.error(chalk.red('\nā --no is required. Cannot preview without material number.\n'));
|
|
89
|
+
}
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
69
92
|
const { inputNo } = await inquirer.prompt([
|
|
70
93
|
{
|
|
71
94
|
type: 'input',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import Table from 'cli-table3';
|
|
4
3
|
import { configManager } from '../../../core/config/manager.js';
|
|
5
4
|
import { apiClient } from '../../../core/api/client.js';
|
|
6
5
|
import { Environment } from '../../../types/index.js';
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
6
|
+
import { CreateWarehouseRequest } from '../../../types/warehouse.js';
|
|
7
|
+
|
|
8
|
+
function formatTable(data: CreateWarehouseRequest): string {
|
|
9
|
+
const lines: string[] = [];
|
|
10
|
+
lines.push(` ${chalk.gray('Code:')} ${data.warehouseCode}`);
|
|
11
|
+
lines.push(` ${chalk.gray('Name:')} ${data.warehouseName || '(not set)'}`);
|
|
12
|
+
if (data.warehouseType) lines.push(` ${chalk.gray('Type:')} ${data.warehouseType}`);
|
|
13
|
+
if (data.warehouseClasses) lines.push(` ${chalk.gray('Classes:')} ${data.warehouseClasses}`);
|
|
14
|
+
if (data.address) lines.push(` ${chalk.gray('Address:')} ${data.address}`);
|
|
15
|
+
if (data.contact) lines.push(` ${chalk.gray('Contact:')} ${data.contact}`);
|
|
16
|
+
if (data.phone) lines.push(` ${chalk.gray('Phone:')} ${data.phone}`);
|
|
17
|
+
if (data.manager) lines.push(` ${chalk.gray('Manager:')} ${data.manager}`);
|
|
18
|
+
if (data.enableLocation !== undefined) {
|
|
19
|
+
lines.push(` ${chalk.gray('Enable Location:')} ${data.enableLocation === 'Y' ? 'Yes' : 'No'}`);
|
|
20
|
+
}
|
|
21
|
+
if (data.enableNegativeInventory !== undefined) {
|
|
22
|
+
lines.push(` ${chalk.gray('Enable Negative Inventory:')} ${data.enableNegativeInventory === 'Y' ? 'Yes' : 'No'}`);
|
|
23
|
+
}
|
|
24
|
+
if (data.remark) lines.push(` ${chalk.gray('Remark:')} ${data.remark}`);
|
|
25
|
+
return lines.join('\n');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createWarehouseCreateCommand(): Command {
|
|
29
|
+
const cmd = new Command('create');
|
|
30
|
+
cmd.description('Create a new warehouse (auto-generates code if not provided)');
|
|
31
|
+
|
|
32
|
+
cmd
|
|
33
|
+
.option('-n, --name <name>', 'Warehouse name (required)')
|
|
34
|
+
.option('-c, --code <code>', 'Warehouse code (auto-generated if not provided)')
|
|
35
|
+
.option('-t, --type <type>', 'Warehouse type')
|
|
36
|
+
.option('--classes <classes>', 'Warehouse classes')
|
|
37
|
+
.option('-a, --address <address>', 'Address')
|
|
38
|
+
.option('--contact <contact>', 'Contact person')
|
|
39
|
+
.option('-p, --phone <phone>', 'Contact phone')
|
|
40
|
+
.option('-m, --manager <manager>', 'Warehouse manager')
|
|
41
|
+
.option('--enable-location', 'Enable location management')
|
|
42
|
+
.option('--disable-location', 'Disable location management')
|
|
43
|
+
.option('--enable-negative-inventory', 'Enable negative inventory')
|
|
44
|
+
.option('--disable-negative-inventory', 'Disable negative inventory')
|
|
45
|
+
.option('--remark <remark>', 'Remark')
|
|
46
|
+
.option('--dry-run', 'Preview without making API call')
|
|
47
|
+
.option('--json', 'Output as JSON');
|
|
48
|
+
|
|
49
|
+
cmd.action(async (options) => {
|
|
50
|
+
const context = configManager.getCurrentContext();
|
|
51
|
+
|
|
52
|
+
let name = options.name as string | undefined;
|
|
53
|
+
let code = options.code as string | undefined;
|
|
54
|
+
const type = options.type as string | undefined;
|
|
55
|
+
const classes = options.classes as string | undefined;
|
|
56
|
+
const address = options.address as string | undefined;
|
|
57
|
+
const contact = options.contact as string | undefined;
|
|
58
|
+
const phone = options.phone as string | undefined;
|
|
59
|
+
const manager = options.manager as string | undefined;
|
|
60
|
+
const enableLocationRaw = options.enableLocation as boolean | undefined;
|
|
61
|
+
const disableLocationRaw = options.disableLocation as boolean | undefined;
|
|
62
|
+
const enableNegativeInventoryRaw = options.enableNegativeInventory as boolean | undefined;
|
|
63
|
+
const disableNegativeInventoryRaw = options.disableNegativeInventory as boolean | undefined;
|
|
64
|
+
const remark = options.remark as string | undefined;
|
|
65
|
+
const dryRun = options.dryRun === true;
|
|
66
|
+
const jsonOutput = options.json === true;
|
|
67
|
+
|
|
68
|
+
if (!name) {
|
|
69
|
+
const { inputName } = await inquirer.prompt([
|
|
70
|
+
{
|
|
71
|
+
type: 'input',
|
|
72
|
+
name: 'inputName',
|
|
73
|
+
message: 'Enter warehouse name:',
|
|
74
|
+
validate: (input: string) => input.trim().length > 0 || 'Warehouse name is required',
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
name = inputName;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!code) {
|
|
81
|
+
const codeResponse = await apiClient.getCodeByType(context.environment, context.tenant, 'TenantWarehouseCode');
|
|
82
|
+
if (codeResponse.success && codeResponse.data) {
|
|
83
|
+
code = codeResponse.data;
|
|
84
|
+
} else {
|
|
85
|
+
const errMsg = codeResponse.error?.message || 'Failed to generate warehouse code';
|
|
86
|
+
if (jsonOutput) {
|
|
87
|
+
console.log(JSON.stringify({ success: false, error: { code: 'CODE_GENERATION_ERROR', message: errMsg } }));
|
|
88
|
+
} else {
|
|
89
|
+
console.error(chalk.red(`\nā Failed to generate warehouse code: ${errMsg}\n`));
|
|
90
|
+
}
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let enableLocation: string | undefined;
|
|
96
|
+
if (enableLocationRaw !== undefined) {
|
|
97
|
+
enableLocation = 'Y';
|
|
98
|
+
} else if (disableLocationRaw !== undefined) {
|
|
99
|
+
enableLocation = 'N';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let enableNegativeInventory: string | undefined;
|
|
103
|
+
if (enableNegativeInventoryRaw !== undefined) {
|
|
104
|
+
enableNegativeInventory = 'Y';
|
|
105
|
+
} else if (disableNegativeInventoryRaw !== undefined) {
|
|
106
|
+
enableNegativeInventory = 'N';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const data: CreateWarehouseRequest = {
|
|
110
|
+
warehouseCode: code!,
|
|
111
|
+
warehouseName: name!,
|
|
112
|
+
warehouseType: type,
|
|
113
|
+
warehouseClasses: classes,
|
|
114
|
+
address: address,
|
|
115
|
+
contact: contact,
|
|
116
|
+
phone: phone,
|
|
117
|
+
manager: manager,
|
|
118
|
+
enableLocation: enableLocation,
|
|
119
|
+
enableNegativeInventory: enableNegativeInventory,
|
|
120
|
+
remark: remark,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
if (dryRun) {
|
|
124
|
+
if (jsonOutput) {
|
|
125
|
+
console.log(JSON.stringify({ success: true, dryRun: true, data }));
|
|
126
|
+
} else {
|
|
127
|
+
console.log(chalk.bold('\nš Dry-Run Mode: No changes will be made\n'));
|
|
128
|
+
console.log(' Warehouse to be created:');
|
|
129
|
+
console.log(formatTable(data));
|
|
130
|
+
console.log();
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!jsonOutput) {
|
|
136
|
+
console.log(chalk.bold('\nš Creating Warehouse\n'));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const response = await apiClient.createWarehouse(context.environment, context.tenant, data);
|
|
140
|
+
|
|
141
|
+
if (!response.success) {
|
|
142
|
+
const errorMsg = response.error?.message || 'Failed to create warehouse';
|
|
143
|
+
const errorCode = response.error?.code || 'CREATE_WAREHOUSE_ERROR';
|
|
144
|
+
if (jsonOutput) {
|
|
145
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
146
|
+
} else {
|
|
147
|
+
console.error(chalk.red(`\nā Failed to create warehouse: ${errorMsg}`));
|
|
148
|
+
if (response.error?.code) {
|
|
149
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
150
|
+
}
|
|
151
|
+
console.error();
|
|
152
|
+
}
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (response.success) {
|
|
157
|
+
const warehouse = response.data as {
|
|
158
|
+
warehouseId?: string;
|
|
159
|
+
warehouseCode?: string;
|
|
160
|
+
warehouseName?: string;
|
|
161
|
+
warehouseType?: string;
|
|
162
|
+
warehouseClasses?: string;
|
|
163
|
+
address?: string;
|
|
164
|
+
contact?: string;
|
|
165
|
+
phone?: string;
|
|
166
|
+
manager?: string;
|
|
167
|
+
enableLocation?: boolean;
|
|
168
|
+
enableNegativeInventory?: boolean;
|
|
169
|
+
remark?: string;
|
|
170
|
+
status?: number;
|
|
171
|
+
createTime?: string;
|
|
172
|
+
} | undefined;
|
|
173
|
+
|
|
174
|
+
if (jsonOutput) {
|
|
175
|
+
console.log(JSON.stringify({ success: true, data: warehouse }));
|
|
176
|
+
} else {
|
|
177
|
+
console.log(chalk.green('ā Warehouse created successfully\n'));
|
|
178
|
+
if (warehouse?.warehouseId) console.log(` ${chalk.gray('Warehouse ID:')} ${chalk.green(String(warehouse.warehouseId))}`);
|
|
179
|
+
if (warehouse?.warehouseCode) console.log(` ${chalk.gray('Code:')} ${warehouse.warehouseCode}`);
|
|
180
|
+
if (warehouse?.warehouseName) console.log(` ${chalk.gray('Name:')} ${warehouse.warehouseName}`);
|
|
181
|
+
if (warehouse?.warehouseType) console.log(` ${chalk.gray('Type:')} ${warehouse.warehouseType}`);
|
|
182
|
+
if (warehouse?.warehouseClasses) console.log(` ${chalk.gray('Classes:')} ${warehouse.warehouseClasses}`);
|
|
183
|
+
if (warehouse?.address) console.log(` ${chalk.gray('Address:')} ${warehouse.address}`);
|
|
184
|
+
if (warehouse?.contact) console.log(` ${chalk.gray('Contact:')} ${warehouse.contact}`);
|
|
185
|
+
if (warehouse?.phone) console.log(` ${chalk.gray('Phone:')} ${warehouse.phone}`);
|
|
186
|
+
if (warehouse?.manager) console.log(` ${chalk.gray('Manager:')} ${warehouse.manager}`);
|
|
187
|
+
if (warehouse?.enableLocation !== undefined) {
|
|
188
|
+
console.log(` ${chalk.gray('Enable Location:')} ${warehouse.enableLocation ? 'Yes' : 'No'}`);
|
|
189
|
+
}
|
|
190
|
+
if (warehouse?.enableNegativeInventory !== undefined) {
|
|
191
|
+
console.log(` ${chalk.gray('Enable Negative Inventory:')} ${warehouse.enableNegativeInventory ? 'Yes' : 'No'}`);
|
|
192
|
+
}
|
|
193
|
+
if (warehouse?.remark) console.log(` ${chalk.gray('Remark:')} ${warehouse.remark}`);
|
|
194
|
+
if (warehouse?.status !== undefined) {
|
|
195
|
+
const statusText = warehouse.status === 1 ? 'Enabled' : 'Disabled';
|
|
196
|
+
console.log(` ${chalk.gray('Status:')} ${chalk.green(statusText)}`);
|
|
197
|
+
}
|
|
198
|
+
console.log();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
return cmd;
|
|
204
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { Environment } from '../../../types/index.js';
|
|
6
|
+
import { Warehouse } from '../../../types/warehouse.js';
|
|
7
|
+
|
|
8
|
+
export function createWarehouseDeleteCommand(): Command {
|
|
9
|
+
const deleteCommand = new Command('delete');
|
|
10
|
+
deleteCommand
|
|
11
|
+
.description('Delete a warehouse')
|
|
12
|
+
.argument('<warehouseId>', 'Warehouse ID')
|
|
13
|
+
.option('--force', 'Skip confirmation and delete directly')
|
|
14
|
+
.option('--dry-run', 'Preview without making API call')
|
|
15
|
+
.option('--json', 'Output as JSON')
|
|
16
|
+
.action(async (warehouseId: string, options: Record<string, unknown>) => {
|
|
17
|
+
const context = configManager.getCurrentContext();
|
|
18
|
+
const environment = context.environment as Environment;
|
|
19
|
+
const tenant = context.tenant;
|
|
20
|
+
const dryRun = options.dryRun === true;
|
|
21
|
+
const jsonOutput = options.json === true;
|
|
22
|
+
|
|
23
|
+
if (!jsonOutput) {
|
|
24
|
+
console.log(chalk.bold(`\nšļø Delete Warehouse (${environment})\n`));
|
|
25
|
+
console.log(chalk.gray(` Warehouse ID: ${warehouseId}`));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let warehouse: Warehouse | undefined;
|
|
29
|
+
try {
|
|
30
|
+
const warehouseResponse = await apiClient.getWarehouse(environment, tenant, warehouseId);
|
|
31
|
+
if (!warehouseResponse.success || !warehouseResponse.data || !('warehouseId' in warehouseResponse.data)) {
|
|
32
|
+
const errMsg = `Warehouse not found: ${warehouseId}`;
|
|
33
|
+
if (jsonOutput) {
|
|
34
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
35
|
+
} else {
|
|
36
|
+
console.error(chalk.red(`\nā ${errMsg}\n`));
|
|
37
|
+
}
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
warehouse = warehouseResponse.data as Warehouse;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
43
|
+
if (jsonOutput) {
|
|
44
|
+
console.log(JSON.stringify({ success: false, error: { code: 'FETCH_ERROR', message: `Failed to fetch warehouse: ${errMsg}` } }));
|
|
45
|
+
} else {
|
|
46
|
+
console.error(chalk.red(`\nā Failed to fetch warehouse: ${errMsg}\n`));
|
|
47
|
+
}
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!jsonOutput) {
|
|
52
|
+
console.log(chalk.gray(` Name: ${warehouse.warehouseName}`));
|
|
53
|
+
console.log(chalk.gray(` Code: ${warehouse.warehouseCode}`));
|
|
54
|
+
if (warehouse.contact) {
|
|
55
|
+
console.log(chalk.gray(` Contact: ${warehouse.contact} (${warehouse.phone || 'N/A'})`));
|
|
56
|
+
}
|
|
57
|
+
if (warehouse.address) {
|
|
58
|
+
console.log(chalk.gray(` Address: ${warehouse.address}`));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (dryRun) {
|
|
63
|
+
if (jsonOutput) {
|
|
64
|
+
console.log(JSON.stringify({ success: true, dryRun: true, warehouse }));
|
|
65
|
+
} else {
|
|
66
|
+
console.log(chalk.cyan('\nš Dry-Run Mode: No actual deletion will be made\n'));
|
|
67
|
+
console.log(chalk.yellow(' To delete, add: --force\n'));
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!options.force) {
|
|
73
|
+
// TODO: add confirmation prompt here
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const response = await apiClient.deleteWarehouse(environment, tenant, warehouseId);
|
|
79
|
+
|
|
80
|
+
if (response.success) {
|
|
81
|
+
if (jsonOutput) {
|
|
82
|
+
console.log(JSON.stringify({ success: true, warehouseId, name: warehouse.warehouseName }));
|
|
83
|
+
} else {
|
|
84
|
+
console.log(chalk.green(`\nā Warehouse "${warehouse.warehouseName}" (ID: ${warehouseId}) deleted\n`));
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
88
|
+
const errorCode = response.error?.code || 'DELETE_ERROR';
|
|
89
|
+
if (jsonOutput) {
|
|
90
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
91
|
+
} else {
|
|
92
|
+
console.error(chalk.red(`\nā Failed to delete warehouse: ${errorMsg}`));
|
|
93
|
+
if (response.error?.code) {
|
|
94
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
95
|
+
}
|
|
96
|
+
console.error();
|
|
97
|
+
}
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
} catch (error) {
|
|
101
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
102
|
+
if (jsonOutput) {
|
|
103
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
104
|
+
} else {
|
|
105
|
+
console.error(chalk.red(`\nā Error: ${errMsg}\n`));
|
|
106
|
+
}
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return deleteCommand;
|
|
112
|
+
}
|