@newpeak/barista-cli 0.1.5 → 0.1.6
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/dist/commands/liberica/currency/create.d.ts +3 -0
- package/dist/commands/liberica/currency/create.d.ts.map +1 -0
- package/dist/commands/liberica/currency/create.js +168 -0
- package/dist/commands/liberica/currency/create.js.map +1 -0
- package/dist/commands/liberica/currency/delete.d.ts +3 -0
- package/dist/commands/liberica/currency/delete.d.ts.map +1 -0
- package/dist/commands/liberica/currency/delete.js +122 -0
- package/dist/commands/liberica/currency/delete.js.map +1 -0
- package/dist/commands/liberica/currency/disable.d.ts +3 -0
- package/dist/commands/liberica/currency/disable.d.ts.map +1 -0
- package/dist/commands/liberica/currency/disable.js +145 -0
- package/dist/commands/liberica/currency/disable.js.map +1 -0
- package/dist/commands/liberica/currency/enable.d.ts +3 -0
- package/dist/commands/liberica/currency/enable.d.ts.map +1 -0
- package/dist/commands/liberica/currency/enable.js +125 -0
- package/dist/commands/liberica/currency/enable.js.map +1 -0
- package/dist/commands/liberica/currency/get.d.ts +3 -0
- package/dist/commands/liberica/currency/get.d.ts.map +1 -0
- package/dist/commands/liberica/currency/get.js +80 -0
- package/dist/commands/liberica/currency/get.js.map +1 -0
- package/dist/commands/liberica/currency/index.d.ts +3 -0
- package/dist/commands/liberica/currency/index.d.ts.map +1 -0
- package/dist/commands/liberica/currency/index.js +21 -0
- package/dist/commands/liberica/currency/index.js.map +1 -0
- package/dist/commands/liberica/currency/list.d.ts +3 -0
- package/dist/commands/liberica/currency/list.d.ts.map +1 -0
- package/dist/commands/liberica/currency/list.js +106 -0
- package/dist/commands/liberica/currency/list.js.map +1 -0
- package/dist/commands/liberica/currency/update.d.ts +3 -0
- package/dist/commands/liberica/currency/update.d.ts.map +1 -0
- package/dist/commands/liberica/currency/update.js +123 -0
- package/dist/commands/liberica/currency/update.js.map +1 -0
- package/dist/commands/liberica/index.d.ts.map +1 -1
- package/dist/commands/liberica/index.js +3 -0
- package/dist/commands/liberica/index.js.map +1 -1
- package/dist/core/api/client.d.ts +10 -0
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +185 -0
- package/dist/core/api/client.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/currency.d.ts +74 -0
- package/dist/types/currency.d.ts.map +1 -0
- package/dist/types/currency.js +2 -0
- package/dist/types/currency.js.map +1 -0
- package/docs/COMMAND_DESIGN_SPEC.md +42 -13
- package/docs/commands/liberica/currency/create.md +145 -0
- package/docs/commands/liberica/currency/delete.md +121 -0
- package/docs/commands/liberica/currency/disable.md +119 -0
- package/docs/commands/liberica/currency/enable.md +115 -0
- package/docs/commands/liberica/currency/get.md +118 -0
- package/docs/commands/liberica/currency/list.md +149 -0
- package/docs/commands/liberica/currency/update.md +141 -0
- package/package.json +1 -1
- package/src/commands/liberica/currency/create.ts +183 -0
- package/src/commands/liberica/currency/delete.ts +124 -0
- package/src/commands/liberica/currency/disable.ts +147 -0
- package/src/commands/liberica/currency/enable.ts +128 -0
- package/src/commands/liberica/currency/get.ts +91 -0
- package/src/commands/liberica/currency/index.ts +23 -0
- package/src/commands/liberica/currency/list.ts +140 -0
- package/src/commands/liberica/currency/update.ts +129 -0
- package/src/commands/liberica/index.ts +3 -0
- package/src/core/api/client.ts +236 -0
- package/src/index.ts +1 -1
- package/src/types/currency.ts +90 -0
- /package/docs/commands/liberica/{materials-create.md → materials/create.md} +0 -0
- /package/docs/commands/liberica/{materials-delete.md → materials/delete.md} +0 -0
- /package/docs/commands/liberica/{materials-disable.md → materials/disable.md} +0 -0
- /package/docs/commands/liberica/{materials-enable.md → materials/enable.md} +0 -0
- /package/docs/commands/liberica/{materials-get.md → materials/get.md} +0 -0
- /package/docs/commands/liberica/{materials-list.md → materials/list.md} +0 -0
- /package/docs/commands/liberica/{materials-update.md → materials/update.md} +0 -0
- /package/docs/commands/liberica/{uoms-create.md → uoms/create.md} +0 -0
- /package/docs/commands/liberica/{uoms-delete.md → uoms/delete.md} +0 -0
- /package/docs/commands/liberica/{uoms-disable.md → uoms/disable.md} +0 -0
- /package/docs/commands/liberica/{uoms-enable.md → uoms/enable.md} +0 -0
- /package/docs/commands/liberica/{uoms-get.md → uoms/get.md} +0 -0
- /package/docs/commands/liberica/{uoms-list.md → uoms/list.md} +0 -0
- /package/docs/commands/liberica/{uoms-update.md → uoms/update.md} +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# barista liberica currency list
|
|
2
|
+
|
|
3
|
+
分页查询币种列表。
|
|
4
|
+
|
|
5
|
+
## 2.1 命令元数据
|
|
6
|
+
|
|
7
|
+
| 字段 | 值 |
|
|
8
|
+
|------|-----|
|
|
9
|
+
| 完整命令 | `barista liberica currency list` |
|
|
10
|
+
| 功能描述 | 分页查询币种列表 |
|
|
11
|
+
| HTTP方法 | GET |
|
|
12
|
+
| 是否需要认证 | ✅ 是 |
|
|
13
|
+
| 是否支持dry-run | ⬜ 否 |
|
|
14
|
+
|
|
15
|
+
## 2.2 后端接口引用
|
|
16
|
+
|
|
17
|
+
### Controller位置
|
|
18
|
+
```
|
|
19
|
+
coffee-liberica-end/
|
|
20
|
+
└── facade/liberica-facade-enterprise/
|
|
21
|
+
└── src/main/java/com/newpeak/liberica/facade/enterprise/controller/finance/
|
|
22
|
+
└── FinanceCurrencyController.java
|
|
23
|
+
└── listCurrencies(@GetResource(path = "/page"))
|
|
24
|
+
└── public ResponseData<PageResult<CurrencyResponse>> listCurrencies(
|
|
25
|
+
@ParameterObject CurrencyRequest request
|
|
26
|
+
)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Request DTO位置
|
|
30
|
+
```
|
|
31
|
+
coffee-liberica-end/
|
|
32
|
+
└── business/liberica-business-finance/finance-api/src/main/java/com/newpeak/liberica/finance/api/pojo/request/CurrencyRequest.java
|
|
33
|
+
├── pageNo: Long (分页页码,从0开始)
|
|
34
|
+
├── pageSize: Long (分页大小)
|
|
35
|
+
├── currencyCode: String (币种编码,如 CNY, USD)
|
|
36
|
+
├── currencyName: String (币种名称)
|
|
37
|
+
└── statusFlag: Integer (状态:1=启用,2=禁用)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Response DTO位置
|
|
41
|
+
```
|
|
42
|
+
coffee-liberica-end/
|
|
43
|
+
└── business/liberica-business-finance/finance-api/src/main/java/com/newpeak/liberica/finance/api/pojo/response/CurrencyResponse.java
|
|
44
|
+
├── currencyId: String
|
|
45
|
+
├── currencyCode: String (3位编码,如 CNY)
|
|
46
|
+
├── currencyName: String (币种名称)
|
|
47
|
+
├── currencySign: String (符号,如 ¥)
|
|
48
|
+
├── statusFlag: Integer (1=启用,2=禁用)
|
|
49
|
+
├── createTime: String
|
|
50
|
+
└── updateTime: String
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 分页包装器
|
|
54
|
+
```
|
|
55
|
+
cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult
|
|
56
|
+
├── totalRows: long
|
|
57
|
+
├── pageSize: long
|
|
58
|
+
├── pageNo: long
|
|
59
|
+
└── rows: List<CurrencyResponse>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 2.3 CLI参数设计
|
|
63
|
+
|
|
64
|
+
### 命令结构
|
|
65
|
+
```
|
|
66
|
+
barista liberica currency list [options]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 全局选项
|
|
70
|
+
| 选项 | 类型 | 说明 |
|
|
71
|
+
|------|------|------|
|
|
72
|
+
| `--env` | string | 目标环境(dev\|test\|prod-cn\|prod-jp) |
|
|
73
|
+
| `--tenant` | string | 租户代码 |
|
|
74
|
+
| `--json` | boolean | JSON输出 |
|
|
75
|
+
|
|
76
|
+
### 命令选项
|
|
77
|
+
| 选项 | 短选项 | 类型 | 必填 | 默认值 | 说明 | 对应DTO字段 |
|
|
78
|
+
|------|--------|------|------|--------|------|-------------|
|
|
79
|
+
| --page | -p | number | ⬜ | 1 | 页码(从1开始) | pageNo (转换:CLI页码-1) |
|
|
80
|
+
| --size | -s | number | ⬜ | 20 | 每页条数 | pageSize |
|
|
81
|
+
| --status | — | string | ⬜ | - | 状态:enable/disable | statusFlag (enable=1, disable=2) |
|
|
82
|
+
| --code | -c | string | ⬜ | - | 币种编码(3位) | currencyCode |
|
|
83
|
+
| --name | -n | string | ⬜ | - | 币种名称 | currencyName |
|
|
84
|
+
|
|
85
|
+
## 2.4 字段映射表
|
|
86
|
+
|
|
87
|
+
| CLI参数 | DTO字段 | 类型转换 | 验证规则 |
|
|
88
|
+
|---------|---------|----------|----------|
|
|
89
|
+
| --page / -p | pageNo | number→Long,CLI页码-1 | >= 1 |
|
|
90
|
+
| --size / -s | pageSize | number→Long | 1-100 |
|
|
91
|
+
| --status | statusFlag | string→Integer | enable=1, disable=2 |
|
|
92
|
+
| --code / -c | currencyCode | string→String | 3位字母 |
|
|
93
|
+
| --name / -n | currencyName | string→String | - |
|
|
94
|
+
|
|
95
|
+
## 2.5 错误码引用
|
|
96
|
+
|
|
97
|
+
### ExceptionEnum位置
|
|
98
|
+
```
|
|
99
|
+
coffee-liberica-end/
|
|
100
|
+
└── business/liberica-business-finance/finance-api/src/main/java/com/newpeak/liberica/finance/api/exception/enums/CurrencyExceptionEnum.java
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 已知错误码
|
|
104
|
+
| 错误码 | 错误消息 | 触发条件 |
|
|
105
|
+
|--------|----------|----------|
|
|
106
|
+
| CURRENCY_NOT_EXIST | 币种不存在 | 查询/编辑/删除时ID不存在 |
|
|
107
|
+
| CURRENCY_CODE_DUPLICATE | 币种编码重复 | 创建/编辑时编码已存在 |
|
|
108
|
+
|
|
109
|
+
## 2.6 权限检查
|
|
110
|
+
|
|
111
|
+
| 检查项 | 位置 | 说明 |
|
|
112
|
+
|--------|------|------|
|
|
113
|
+
| 注解 | 无需权限 | 登录用户可访问 |
|
|
114
|
+
|
|
115
|
+
## 2.7 实现要点
|
|
116
|
+
|
|
117
|
+
1. **分页默认值**:page=1, size=20
|
|
118
|
+
2. **分页转换**:CLI使用1-based页码,API使用0-based页码(调用时需减1)
|
|
119
|
+
3. **编码格式**:currencyCode 为3位字母编码(ISO 4217标准,如 CNY, USD, EUR)
|
|
120
|
+
4. **状态映射**:CLI参数 `enable`/`disable` 映射到 API 值 `1`/`2`
|
|
121
|
+
5. **无结果处理**:返回空列表,不抛出异常
|
|
122
|
+
6. **tenantId来源**:来自 JWT token(无需 X-TENANT-ID header)
|
|
123
|
+
7. **输出格式**:表格形式展示,分页信息在底部显示
|
|
124
|
+
8. **API路径**:GET `/api/enterprise/finance/currency/page`
|
|
125
|
+
|
|
126
|
+
## 2.8 示例用法
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# 默认分页
|
|
130
|
+
barista liberica currency list
|
|
131
|
+
|
|
132
|
+
# 指定页码和每页条数
|
|
133
|
+
barista liberica currency list --page 2 --size 50
|
|
134
|
+
|
|
135
|
+
# 按状态筛选
|
|
136
|
+
barista liberica currency list --status enable
|
|
137
|
+
|
|
138
|
+
# 按编码筛选
|
|
139
|
+
barista liberica currency list --code "CNY"
|
|
140
|
+
|
|
141
|
+
# 按名称搜索
|
|
142
|
+
barista liberica currency list --name "人民币"
|
|
143
|
+
|
|
144
|
+
# 组合筛选
|
|
145
|
+
barista liberica currency list --page 1 --size 10 --status enable --code "CNY"
|
|
146
|
+
|
|
147
|
+
# JSON 输出(便于脚本处理)
|
|
148
|
+
barista liberica currency list --page 1 --size 20 --json
|
|
149
|
+
```
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# barista liberica currency update
|
|
2
|
+
|
|
3
|
+
更新币种信息。
|
|
4
|
+
|
|
5
|
+
## 2.1 命令元数据
|
|
6
|
+
|
|
7
|
+
| 字段 | 值 |
|
|
8
|
+
|------|-----|
|
|
9
|
+
| 完整命令 | `barista liberica currency update <currency-id>` |
|
|
10
|
+
| 功能描述 | 更新币种信息 |
|
|
11
|
+
| HTTP方法 | POST |
|
|
12
|
+
| 是否需要认证 | ✅ 是 |
|
|
13
|
+
| 是否支持dry-run | ✅ 是 |
|
|
14
|
+
|
|
15
|
+
## 2.2 后端接口引用
|
|
16
|
+
|
|
17
|
+
### Controller位置
|
|
18
|
+
```
|
|
19
|
+
coffee-liberica-end/
|
|
20
|
+
└── facade/liberica-facade-enterprise/
|
|
21
|
+
└── src/main/java/com/newpeak/liberica/facade/enterprise/controller/finance/
|
|
22
|
+
└── FinanceCurrencyController.java
|
|
23
|
+
└── editCurrency(@PostResource(path = "/edit"))
|
|
24
|
+
└── public ResponseData<CurrencyResponse> editCurrency(
|
|
25
|
+
@RequestBody @Validated CurrencyRequest request
|
|
26
|
+
)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Request DTO位置
|
|
30
|
+
```
|
|
31
|
+
coffee-liberica-end/
|
|
32
|
+
└── business/liberica-business-finance/finance-api/src/main/java/com/newpeak/liberica/finance/api/pojo/request/CurrencyRequest.java
|
|
33
|
+
├── currencyId: String (@NotBlank)
|
|
34
|
+
├── currencyCode: String (@NotBlank, 3位编码)
|
|
35
|
+
├── currencyName: String (@NotBlank)
|
|
36
|
+
├── currencySign: String (符号)
|
|
37
|
+
└── statusFlag: Integer (1=启用, 2=禁用)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Response DTO位置
|
|
41
|
+
```
|
|
42
|
+
coffee-liberica-end/
|
|
43
|
+
└── business/liberica-business-finance/finance-api/src/main/java/com/newpeak/liberica/finance/api/pojo/response/CurrencyResponse.java
|
|
44
|
+
├── currencyId: String
|
|
45
|
+
├── currencyCode: String
|
|
46
|
+
├── currencyName: String
|
|
47
|
+
├── currencySign: String
|
|
48
|
+
├── statusFlag: Integer
|
|
49
|
+
├── createTime: String
|
|
50
|
+
└── updateTime: String
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 2.3 CLI参数设计
|
|
54
|
+
|
|
55
|
+
### 命令结构
|
|
56
|
+
```
|
|
57
|
+
barista liberica currency update <currency-id> [options]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 全局选项
|
|
61
|
+
| 选项 | 类型 | 说明 |
|
|
62
|
+
|------|------|------|
|
|
63
|
+
| `--env` | string | 目标环境(dev\|test\|prod-cn\|prod-jp) |
|
|
64
|
+
| `--tenant` | string | 租户代码 |
|
|
65
|
+
| `--dry-run` | boolean | 预览模式 |
|
|
66
|
+
| `--json` | boolean | JSON输出 |
|
|
67
|
+
|
|
68
|
+
### 位置参数
|
|
69
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
70
|
+
|------|------|------|------|
|
|
71
|
+
| currency-id | string | ✅ | 币种ID |
|
|
72
|
+
|
|
73
|
+
### 命令选项
|
|
74
|
+
| 选项 | 短选项 | 类型 | 必填 | 默认值 | 说明 | 对应DTO字段 |
|
|
75
|
+
|------|--------|------|------|--------|------|-------------|
|
|
76
|
+
| --currency-id | -i | string | ⬜ | - | 币种ID(与位置参数互斥) | currencyId |
|
|
77
|
+
| --code | -c | string | ✅ | - | 币种编码(3位) | currencyCode |
|
|
78
|
+
| --name | -n | string | ✅ | - | 币种名称 | currencyName |
|
|
79
|
+
| --sign | -S | string | ⬜ | - | 币种符号 | currencySign |
|
|
80
|
+
|
|
81
|
+
## 2.4 字段映射表
|
|
82
|
+
|
|
83
|
+
| CLI参数 | DTO字段 | 类型转换 | 验证规则 |
|
|
84
|
+
|---------|---------|----------|----------|
|
|
85
|
+
| currency-id (位置参数) | currencyId | string→String | @NotBlank |
|
|
86
|
+
| --currency-id / -i | currencyId | string→String | @NotBlank |
|
|
87
|
+
| --code / -c | currencyCode | string→String | @NotBlank, 3位字母 |
|
|
88
|
+
| --name / -n | currencyName | string→String | @NotBlank, max=255 |
|
|
89
|
+
| --sign / -S | currencySign | string→String | max=10 |
|
|
90
|
+
|
|
91
|
+
## 2.5 错误码引用
|
|
92
|
+
|
|
93
|
+
### ExceptionEnum位置
|
|
94
|
+
```
|
|
95
|
+
coffee-liberica-end/
|
|
96
|
+
└── business/liberica-business-finance/finance-api/src/main/java/com/newpeak/liberica/finance/api/exception/enums/CurrencyExceptionEnum.java
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 已知错误码
|
|
100
|
+
| 错误码 | 错误消息 | 触发条件 |
|
|
101
|
+
|--------|----------|----------|
|
|
102
|
+
| CURRENCY_NOT_EXIST | 币种不存在 | 币种不存在 |
|
|
103
|
+
| CURRENCY_CODE_DUPLICATE | 币种编码重复 | 编码重复 |
|
|
104
|
+
| CURRENCY_CODE_EMPTY | 币种编码不能为空 | 编码为空 |
|
|
105
|
+
| CURRENCY_NAME_EMPTY | 币种名称不能为空 | 名称为空 |
|
|
106
|
+
|
|
107
|
+
## 2.6 权限检查
|
|
108
|
+
|
|
109
|
+
| 检查项 | 位置 | 说明 |
|
|
110
|
+
|--------|------|------|
|
|
111
|
+
| 注解 | FinanceCurrencyController.java | 需要 `finance_currency:edit` 权限 |
|
|
112
|
+
|
|
113
|
+
## 2.7 实现要点
|
|
114
|
+
|
|
115
|
+
1. **ID必填**:currencyId为必填参数(位置参数或 --currency-id 选项)
|
|
116
|
+
2. **必填字段**:currencyCode 和 currencyName 为必填参数(通常需要先获取现有值再修改)
|
|
117
|
+
3. **dry-run 支持**:支持 `--dry-run` 预览模式,显示将要更新的字段变化
|
|
118
|
+
4. **完整更新**:后端可能是完整更新模式,需要提供所有字段值
|
|
119
|
+
5. **建议用法**:先执行 `barista liberica currency get <id>` 获取当前值,再更新指定字段
|
|
120
|
+
6. **API路径**:POST `/api/enterprise/finance/currency/edit`
|
|
121
|
+
7. **成功响应**:返回更新后的币种详情
|
|
122
|
+
|
|
123
|
+
## 2.8 示例用法
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# 更新币种(通过位置参数)
|
|
127
|
+
barista liberica currency update "1234567890123456789" --code "CNY" --name "人民币"
|
|
128
|
+
|
|
129
|
+
# 更新币种(通过选项参数)
|
|
130
|
+
barista liberica currency update --currency-id "1234567890123456789" --code "CNY" --name "人民币"
|
|
131
|
+
barista liberica currency update -i "1234567890123456789" -c "CNY" -n "人民币"
|
|
132
|
+
|
|
133
|
+
# 更新符号
|
|
134
|
+
barista liberica currency update "1234567890123456789" --code "USD" --name "美元" --sign "$"
|
|
135
|
+
|
|
136
|
+
# 预览模式(dry-run)
|
|
137
|
+
barista liberica currency update "1234567890123456789" --code "EUR" --name "欧元" --dry-run
|
|
138
|
+
|
|
139
|
+
# JSON 输出
|
|
140
|
+
barista liberica currency update "1234567890123456789" --code "CNY" --name "人民币" --json
|
|
141
|
+
```
|
package/package.json
CHANGED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
5
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
6
|
+
import { CreateCurrencyRequest, CurrencyDefault } from '../../../types/currency.js';
|
|
7
|
+
|
|
8
|
+
function formatTable(data: CreateCurrencyRequest): string {
|
|
9
|
+
const lines: string[] = [];
|
|
10
|
+
lines.push(` ${chalk.gray('Code:')} ${data.currencyCode || '(not set)'}`);
|
|
11
|
+
lines.push(` ${chalk.gray('Name:')} ${data.currencyName || '(auto-filled from API)'}`);
|
|
12
|
+
lines.push(` ${chalk.gray('Sign:')} ${data.currencySign || '(auto-filled from API)'}`);
|
|
13
|
+
if (data.currencyRate) lines.push(` ${chalk.gray('Rate:')} ${data.currencyRate}`);
|
|
14
|
+
if (data.unitPriceFractionPlaces !== undefined) lines.push(` ${chalk.gray('Unit Fraction Places:')} ${data.unitPriceFractionPlaces}`);
|
|
15
|
+
if (data.amountFractionPlaces !== undefined) lines.push(` ${chalk.gray('Amount Fraction Places:')} ${data.amountFractionPlaces}`);
|
|
16
|
+
if (data.remark) lines.push(` ${chalk.gray('Remark:')} ${data.remark}`);
|
|
17
|
+
return lines.join('\n');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createCurrencyCreateCommand(): Command {
|
|
21
|
+
const cmd = new Command('create');
|
|
22
|
+
cmd.description('Create a new currency (auto-fills name and sign from getCurrencyDefault)');
|
|
23
|
+
|
|
24
|
+
cmd
|
|
25
|
+
.option('-c, --code <code>', 'Currency code (3 uppercase letters, e.g., CNY, USD)')
|
|
26
|
+
.option('-r, --rate <rate>', 'Currency exchange rate')
|
|
27
|
+
.option('--unit-fraction <places>', 'Unit price fraction places', '2')
|
|
28
|
+
.option('--amount-fraction <places>', 'Amount fraction places', '2')
|
|
29
|
+
.option('--remark <text>', 'Remark')
|
|
30
|
+
.option('--dry-run', 'Preview without making API call')
|
|
31
|
+
.option('--json', 'Output as JSON');
|
|
32
|
+
|
|
33
|
+
cmd.action(async () => {
|
|
34
|
+
const context = configManager.getCurrentContext();
|
|
35
|
+
const opts = cmd.opts();
|
|
36
|
+
|
|
37
|
+
const dryRun = opts.dryRun === true;
|
|
38
|
+
const outputJson = (opts as Record<string, unknown>).json === true || process.argv.includes('--json');
|
|
39
|
+
|
|
40
|
+
let code = opts.code as string | undefined;
|
|
41
|
+
|
|
42
|
+
if (!code) {
|
|
43
|
+
const { inputCode } = await inquirer.prompt([
|
|
44
|
+
{
|
|
45
|
+
type: 'input',
|
|
46
|
+
name: 'inputCode',
|
|
47
|
+
message: 'Enter currency code (3 letters, e.g., CNY, USD):',
|
|
48
|
+
validate: (input: string) => {
|
|
49
|
+
const trimmed = input.trim().toUpperCase();
|
|
50
|
+
if (!trimmed) return 'Currency code is required';
|
|
51
|
+
if (!/^[A-Z]{3}$/.test(trimmed)) return 'Currency code must be 3 uppercase letters (e.g., CNY, USD)';
|
|
52
|
+
return true;
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
code = inputCode.trim().toUpperCase();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!/^[A-Z]{3}$/.test(code!)) {
|
|
60
|
+
const errMsg = 'Currency code must be 3 uppercase letters (e.g., CNY, USD)';
|
|
61
|
+
if (outputJson) {
|
|
62
|
+
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_CODE', message: errMsg } }));
|
|
63
|
+
} else {
|
|
64
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
65
|
+
}
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const validatedCode = code!;
|
|
70
|
+
|
|
71
|
+
if (!outputJson) {
|
|
72
|
+
console.log(chalk.bold('\n🔍 Fetching currency default info...\n'));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const defaultResponse = await apiClient.getCurrencyDefault(context.environment, context.tenant, validatedCode);
|
|
76
|
+
|
|
77
|
+
if (!defaultResponse.success || !defaultResponse.data) {
|
|
78
|
+
const errMsg = defaultResponse.error?.message || `Failed to fetch currency default for ${validatedCode}`;
|
|
79
|
+
if (outputJson) {
|
|
80
|
+
console.log(JSON.stringify({ success: false, error: { code: 'DEFAULT_FETCH_ERROR', message: errMsg } }));
|
|
81
|
+
} else {
|
|
82
|
+
console.error(chalk.red(`\n✗ Failed to fetch currency default: ${errMsg}`));
|
|
83
|
+
if (defaultResponse.error?.code) {
|
|
84
|
+
console.error(chalk.gray(` Error code: ${defaultResponse.error.code}`));
|
|
85
|
+
}
|
|
86
|
+
console.error();
|
|
87
|
+
}
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const defaultData = defaultResponse.data as CurrencyDefault;
|
|
92
|
+
|
|
93
|
+
const rate = opts.rate as string | undefined;
|
|
94
|
+
const unitFractionPlaces = parseInt(opts.unitFraction as string, 10) || 2;
|
|
95
|
+
const amountFractionPlaces = parseInt(opts.amountFraction as string, 10) || 2;
|
|
96
|
+
const remark = opts.remark as string | undefined;
|
|
97
|
+
|
|
98
|
+
const data: CreateCurrencyRequest = {
|
|
99
|
+
currencyCode: validatedCode,
|
|
100
|
+
currencyName: defaultData.currencyName,
|
|
101
|
+
currencySign: defaultData.currencySign,
|
|
102
|
+
currencyRate: rate,
|
|
103
|
+
unitPriceFractionPlaces: unitFractionPlaces,
|
|
104
|
+
amountFractionPlaces: amountFractionPlaces,
|
|
105
|
+
remark: remark,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
Object.keys(data).forEach(key => {
|
|
109
|
+
if (data[key as keyof CreateCurrencyRequest] === undefined) {
|
|
110
|
+
delete data[key as keyof CreateCurrencyRequest];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (dryRun) {
|
|
115
|
+
if (outputJson) {
|
|
116
|
+
console.log(JSON.stringify({ success: true, dryRun: true, data }));
|
|
117
|
+
} else {
|
|
118
|
+
console.log(chalk.bold('\n🔍 Dry-Run Mode: No changes will be made\n'));
|
|
119
|
+
console.log(' Currency to be created:');
|
|
120
|
+
console.log(formatTable(data));
|
|
121
|
+
console.log();
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!outputJson) {
|
|
127
|
+
console.log(chalk.bold('\n📝 Creating Currency\n'));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const response = await apiClient.createCurrency(context.environment, context.tenant, data);
|
|
131
|
+
|
|
132
|
+
if (!response.success) {
|
|
133
|
+
const errorMsg = response.error?.message || 'Failed to create currency';
|
|
134
|
+
const errorCode = response.error?.code || 'CREATE_CURRENCY_ERROR';
|
|
135
|
+
if (outputJson) {
|
|
136
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
137
|
+
} else {
|
|
138
|
+
console.error(chalk.red(`\n✗ Failed to create currency: ${errorMsg}`));
|
|
139
|
+
if (response.error?.code) {
|
|
140
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
141
|
+
}
|
|
142
|
+
console.error();
|
|
143
|
+
}
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (response.success) {
|
|
148
|
+
const currency = response.data as {
|
|
149
|
+
currencyId?: string;
|
|
150
|
+
currencyCode?: string;
|
|
151
|
+
currencyName?: string;
|
|
152
|
+
currencySign?: string;
|
|
153
|
+
currencyRate?: string;
|
|
154
|
+
unitPriceFractionPlaces?: number;
|
|
155
|
+
amountFractionPlaces?: number;
|
|
156
|
+
statusFlag?: number;
|
|
157
|
+
remark?: string;
|
|
158
|
+
createTime?: string;
|
|
159
|
+
} | undefined;
|
|
160
|
+
|
|
161
|
+
if (outputJson) {
|
|
162
|
+
console.log(JSON.stringify({ success: true, data: currency }));
|
|
163
|
+
} else {
|
|
164
|
+
console.log(chalk.green('✓ Currency created successfully\n'));
|
|
165
|
+
if (currency?.currencyId) console.log(` ${chalk.gray('Currency ID:')} ${chalk.green(String(currency.currencyId))}`);
|
|
166
|
+
if (currency?.currencyCode) console.log(` ${chalk.gray('Code:')} ${currency.currencyCode}`);
|
|
167
|
+
if (currency?.currencyName) console.log(` ${chalk.gray('Name:')} ${currency.currencyName}`);
|
|
168
|
+
if (currency?.currencySign) console.log(` ${chalk.gray('Sign:')} ${currency.currencySign}`);
|
|
169
|
+
if (currency?.currencyRate) console.log(` ${chalk.gray('Rate:')} ${currency.currencyRate}`);
|
|
170
|
+
if (currency?.unitPriceFractionPlaces !== undefined) console.log(` ${chalk.gray('Unit Fraction:')} ${currency.unitPriceFractionPlaces}`);
|
|
171
|
+
if (currency?.amountFractionPlaces !== undefined) console.log(` ${chalk.gray('Amount Fraction:')} ${currency.amountFractionPlaces}`);
|
|
172
|
+
if (currency?.statusFlag !== undefined) {
|
|
173
|
+
const statusText = currency.statusFlag === 1 ? 'Enabled' : 'Disabled';
|
|
174
|
+
console.log(` ${chalk.gray('Status:')} ${chalk.green(statusText)}`);
|
|
175
|
+
}
|
|
176
|
+
if (currency?.remark) console.log(` ${chalk.gray('Remark:')} ${currency.remark}`);
|
|
177
|
+
console.log();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
return cmd;
|
|
183
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
5
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
6
|
+
import { Environment } from '../../../types/index.js';
|
|
7
|
+
import { Currency } from '../../../types/currency.js';
|
|
8
|
+
|
|
9
|
+
export function createCurrencyDeleteCommand(): Command {
|
|
10
|
+
const deleteCommand = new Command('delete');
|
|
11
|
+
deleteCommand
|
|
12
|
+
.description('Delete a currency')
|
|
13
|
+
.argument('<currencyId>', 'Currency ID')
|
|
14
|
+
.option('--force', 'Skip confirmation and delete directly')
|
|
15
|
+
.option('--dry-run', 'Preview the operation without executing')
|
|
16
|
+
.option('--json', 'Output as JSON')
|
|
17
|
+
.action(async (currencyId: string, options: Record<string, unknown>) => {
|
|
18
|
+
const context = configManager.getCurrentContext();
|
|
19
|
+
const environment = context.environment as Environment;
|
|
20
|
+
const tenant = context.tenant;
|
|
21
|
+
const jsonOutput = options.json === true;
|
|
22
|
+
|
|
23
|
+
if (!jsonOutput) {
|
|
24
|
+
console.log(chalk.bold(`\n🗑️ Delete Currency (${environment})\n`));
|
|
25
|
+
console.log(chalk.gray(` Currency ID: ${currencyId}`));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (options.dryRun) {
|
|
29
|
+
if (jsonOutput) {
|
|
30
|
+
console.log(JSON.stringify({ success: true, dryRun: true, currencyId }));
|
|
31
|
+
} else {
|
|
32
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual API call will be made\n'));
|
|
33
|
+
console.log(chalk.gray(' This operation will delete the currency.'));
|
|
34
|
+
console.log();
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let currency: Currency | undefined;
|
|
40
|
+
try {
|
|
41
|
+
const currencyResponse = await apiClient.getCurrency(environment, tenant, currencyId);
|
|
42
|
+
if (!currencyResponse.success || !currencyResponse.data || !('currencyId' in currencyResponse.data)) {
|
|
43
|
+
const errMsg = `Currency not found: ${currencyId}`;
|
|
44
|
+
if (jsonOutput) {
|
|
45
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
46
|
+
} else {
|
|
47
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
48
|
+
}
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
currency = currencyResponse.data as Currency;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
54
|
+
if (jsonOutput) {
|
|
55
|
+
console.log(JSON.stringify({ success: false, error: { code: 'FETCH_ERROR', message: `Failed to fetch currency: ${errMsg}` } }));
|
|
56
|
+
} else {
|
|
57
|
+
console.error(chalk.red(`\n✗ Failed to fetch currency: ${errMsg}\n`));
|
|
58
|
+
}
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!options.force) {
|
|
63
|
+
if (!jsonOutput) {
|
|
64
|
+
console.log(chalk.gray(` Name: ${currency.currencyName}`));
|
|
65
|
+
console.log(chalk.gray(` Code: ${currency.currencyCode}`));
|
|
66
|
+
console.log(chalk.gray(` Sign: ${currency.currencySign}`));
|
|
67
|
+
if (currency.currencyRate !== undefined) {
|
|
68
|
+
console.log(chalk.gray(` Rate: ${currency.currencyRate}`));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const { confirm } = await inquirer.prompt([
|
|
73
|
+
{
|
|
74
|
+
type: 'confirm',
|
|
75
|
+
name: 'confirm',
|
|
76
|
+
message: `Delete currency "${currency.currencyName}" (${currency.currencyCode})? This action cannot be undone.`,
|
|
77
|
+
default: false,
|
|
78
|
+
},
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
if (!confirm) {
|
|
82
|
+
if (!jsonOutput) {
|
|
83
|
+
console.log(chalk.gray('\n Operation cancelled.\n'));
|
|
84
|
+
}
|
|
85
|
+
process.exit(0);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const response = await apiClient.deleteCurrency(environment, tenant, currencyId);
|
|
91
|
+
|
|
92
|
+
if (response.success) {
|
|
93
|
+
if (jsonOutput) {
|
|
94
|
+
console.log(JSON.stringify({ success: true, currencyId, name: currency.currencyName }));
|
|
95
|
+
} else {
|
|
96
|
+
console.log(chalk.green(`\n✓ Currency "${currency.currencyName}" (ID: ${currencyId}) deleted\n`));
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
100
|
+
const errorCode = response.error?.code || 'DELETE_ERROR';
|
|
101
|
+
if (jsonOutput) {
|
|
102
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
103
|
+
} else {
|
|
104
|
+
console.error(chalk.red(`\n✗ Failed to delete currency: ${errorMsg}`));
|
|
105
|
+
if (response.error?.code) {
|
|
106
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
107
|
+
}
|
|
108
|
+
console.error();
|
|
109
|
+
}
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
114
|
+
if (jsonOutput) {
|
|
115
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
116
|
+
} else {
|
|
117
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
118
|
+
}
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return deleteCommand;
|
|
124
|
+
}
|