@newpeak/barista-cli 0.1.7 → 0.1.9
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.md +10 -10
- package/dist/commands/liberica/calendar/index.d.ts +3 -0
- package/dist/commands/liberica/calendar/index.d.ts.map +1 -0
- package/dist/commands/liberica/calendar/index.js +11 -0
- package/dist/commands/liberica/calendar/index.js.map +1 -0
- package/dist/commands/liberica/calendar/list.d.ts +3 -0
- package/dist/commands/liberica/calendar/list.d.ts.map +1 -0
- package/dist/commands/liberica/calendar/list.js +181 -0
- package/dist/commands/liberica/calendar/list.js.map +1 -0
- package/dist/commands/liberica/calendar/set.d.ts +3 -0
- package/dist/commands/liberica/calendar/set.d.ts.map +1 -0
- package/dist/commands/liberica/calendar/set.js +120 -0
- package/dist/commands/liberica/calendar/set.js.map +1 -0
- package/dist/commands/liberica/client-contacts/create.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/create.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/create.js +132 -0
- package/dist/commands/liberica/client-contacts/create.js.map +1 -0
- package/dist/commands/liberica/client-contacts/delete.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/delete.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/delete.js +139 -0
- package/dist/commands/liberica/client-contacts/delete.js.map +1 -0
- package/dist/commands/liberica/client-contacts/get.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/get.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/get.js +92 -0
- package/dist/commands/liberica/client-contacts/get.js.map +1 -0
- package/dist/commands/liberica/client-contacts/index.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/index.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/index.js +17 -0
- package/dist/commands/liberica/client-contacts/index.js.map +1 -0
- package/dist/commands/liberica/client-contacts/list.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/list.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/list.js +92 -0
- package/dist/commands/liberica/client-contacts/list.js.map +1 -0
- package/dist/commands/liberica/client-contacts/update.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/update.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/update.js +156 -0
- package/dist/commands/liberica/client-contacts/update.js.map +1 -0
- package/dist/commands/liberica/dict-types/get.d.ts +3 -0
- package/dist/commands/liberica/dict-types/get.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/get.js +62 -0
- package/dist/commands/liberica/dict-types/get.js.map +1 -0
- package/dist/commands/liberica/dict-types/index.d.ts +3 -0
- package/dist/commands/liberica/dict-types/index.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/index.js +13 -0
- package/dist/commands/liberica/dict-types/index.js.map +1 -0
- package/dist/commands/liberica/dict-types/list.d.ts +3 -0
- package/dist/commands/liberica/dict-types/list.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/list.js +91 -0
- package/dist/commands/liberica/dict-types/list.js.map +1 -0
- package/dist/commands/liberica/dict-types/update.d.ts +3 -0
- package/dist/commands/liberica/dict-types/update.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/update.js +127 -0
- package/dist/commands/liberica/dict-types/update.js.map +1 -0
- package/dist/commands/liberica/dicts/create.d.ts +3 -0
- package/dist/commands/liberica/dicts/create.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/create.js +157 -0
- package/dist/commands/liberica/dicts/create.js.map +1 -0
- package/dist/commands/liberica/dicts/delete.d.ts +3 -0
- package/dist/commands/liberica/dicts/delete.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/delete.js +106 -0
- package/dist/commands/liberica/dicts/delete.js.map +1 -0
- package/dist/commands/liberica/dicts/get.d.ts +3 -0
- package/dist/commands/liberica/dicts/get.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/get.js +69 -0
- package/dist/commands/liberica/dicts/get.js.map +1 -0
- package/dist/commands/liberica/dicts/index.d.ts +3 -0
- package/dist/commands/liberica/dicts/index.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/index.js +17 -0
- package/dist/commands/liberica/dicts/index.js.map +1 -0
- package/dist/commands/liberica/dicts/list.d.ts +3 -0
- package/dist/commands/liberica/dicts/list.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/list.js +88 -0
- package/dist/commands/liberica/dicts/list.js.map +1 -0
- package/dist/commands/liberica/dicts/update.d.ts +3 -0
- package/dist/commands/liberica/dicts/update.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/update.js +112 -0
- package/dist/commands/liberica/dicts/update.js.map +1 -0
- package/dist/commands/liberica/index.d.ts.map +1 -1
- package/dist/commands/liberica/index.js +20 -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 +13 -6
- package/dist/commands/liberica/materials/create.js.map +1 -1
- package/dist/commands/liberica/materials/update.js +1 -1
- package/dist/commands/liberica/materials/update.js.map +1 -1
- package/dist/commands/liberica/mould/get.d.ts +3 -0
- package/dist/commands/liberica/mould/get.d.ts.map +1 -0
- package/dist/commands/liberica/mould/get.js +90 -0
- package/dist/commands/liberica/mould/get.js.map +1 -0
- package/dist/commands/liberica/mould/index.d.ts +3 -0
- package/dist/commands/liberica/mould/index.d.ts.map +1 -0
- package/dist/commands/liberica/mould/index.js +15 -0
- package/dist/commands/liberica/mould/index.js.map +1 -0
- package/dist/commands/liberica/mould/list.d.ts +3 -0
- package/dist/commands/liberica/mould/list.d.ts.map +1 -0
- package/dist/commands/liberica/mould/list.js +114 -0
- package/dist/commands/liberica/mould/list.js.map +1 -0
- package/dist/commands/liberica/mould/set-status.d.ts +3 -0
- package/dist/commands/liberica/mould/set-status.d.ts.map +1 -0
- package/dist/commands/liberica/mould/set-status.js +84 -0
- package/dist/commands/liberica/mould/set-status.js.map +1 -0
- package/dist/commands/liberica/mould/stock-in.d.ts +3 -0
- package/dist/commands/liberica/mould/stock-in.d.ts.map +1 -0
- package/dist/commands/liberica/mould/stock-in.js +160 -0
- package/dist/commands/liberica/mould/stock-in.js.map +1 -0
- package/dist/commands/liberica/operations/active.d.ts +3 -0
- package/dist/commands/liberica/operations/active.d.ts.map +1 -0
- package/dist/commands/liberica/operations/active.js +152 -0
- package/dist/commands/liberica/operations/active.js.map +1 -0
- package/dist/commands/liberica/operations/batch-delete.d.ts +3 -0
- package/dist/commands/liberica/operations/batch-delete.d.ts.map +1 -0
- package/dist/commands/liberica/operations/batch-delete.js +130 -0
- package/dist/commands/liberica/operations/batch-delete.js.map +1 -0
- package/dist/commands/liberica/operations/copy.d.ts +3 -0
- package/dist/commands/liberica/operations/copy.d.ts.map +1 -0
- package/dist/commands/liberica/operations/copy.js +137 -0
- package/dist/commands/liberica/operations/copy.js.map +1 -0
- package/dist/commands/liberica/operations/create.d.ts +3 -0
- package/dist/commands/liberica/operations/create.d.ts.map +1 -0
- package/dist/commands/liberica/operations/create.js +212 -0
- package/dist/commands/liberica/operations/create.js.map +1 -0
- package/dist/commands/liberica/operations/deactive.d.ts +3 -0
- package/dist/commands/liberica/operations/deactive.d.ts.map +1 -0
- package/dist/commands/liberica/operations/deactive.js +152 -0
- package/dist/commands/liberica/operations/deactive.js.map +1 -0
- package/dist/commands/liberica/operations/delete.d.ts +3 -0
- package/dist/commands/liberica/operations/delete.d.ts.map +1 -0
- package/dist/commands/liberica/operations/delete.js +128 -0
- package/dist/commands/liberica/operations/delete.js.map +1 -0
- package/dist/commands/liberica/operations/get.d.ts +3 -0
- package/dist/commands/liberica/operations/get.d.ts.map +1 -0
- package/dist/commands/liberica/operations/get.js +93 -0
- package/dist/commands/liberica/operations/get.js.map +1 -0
- package/dist/commands/liberica/operations/index.d.ts +3 -0
- package/dist/commands/liberica/operations/index.d.ts.map +1 -0
- package/dist/commands/liberica/operations/index.js +25 -0
- package/dist/commands/liberica/operations/index.js.map +1 -0
- package/dist/commands/liberica/operations/list.d.ts +3 -0
- package/dist/commands/liberica/operations/list.d.ts.map +1 -0
- package/dist/commands/liberica/operations/list.js +141 -0
- package/dist/commands/liberica/operations/list.js.map +1 -0
- package/dist/commands/liberica/operations/update.d.ts +3 -0
- package/dist/commands/liberica/operations/update.d.ts.map +1 -0
- package/dist/commands/liberica/operations/update.js +208 -0
- package/dist/commands/liberica/operations/update.js.map +1 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.d.ts +2 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.d.ts.map +1 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.js +41 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.js.map +1 -0
- package/dist/commands/liberica/stock/__tests__/list.test.d.ts +2 -0
- package/dist/commands/liberica/stock/__tests__/list.test.d.ts.map +1 -0
- package/dist/commands/liberica/stock/__tests__/list.test.js +39 -0
- package/dist/commands/liberica/stock/__tests__/list.test.js.map +1 -0
- package/dist/commands/liberica/stock/index.d.ts +3 -0
- package/dist/commands/liberica/stock/index.d.ts.map +1 -0
- package/dist/commands/liberica/stock/index.js +11 -0
- package/dist/commands/liberica/stock/index.js.map +1 -0
- package/dist/commands/liberica/stock/ledger.d.ts +3 -0
- package/dist/commands/liberica/stock/ledger.d.ts.map +1 -0
- package/dist/commands/liberica/stock/ledger.js +154 -0
- package/dist/commands/liberica/stock/ledger.js.map +1 -0
- package/dist/commands/liberica/stock/list.d.ts +3 -0
- package/dist/commands/liberica/stock/list.d.ts.map +1 -0
- package/dist/commands/liberica/stock/list.js +127 -0
- package/dist/commands/liberica/stock/list.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/create.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/create.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/create.js +129 -0
- package/dist/commands/liberica/supplier-contacts/create.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/delete.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/delete.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/delete.js +88 -0
- package/dist/commands/liberica/supplier-contacts/delete.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/get.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/get.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/get.js +84 -0
- package/dist/commands/liberica/supplier-contacts/get.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/index.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/index.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/index.js +17 -0
- package/dist/commands/liberica/supplier-contacts/index.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/list.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/list.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/list.js +98 -0
- package/dist/commands/liberica/supplier-contacts/list.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/update.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/update.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/update.js +136 -0
- package/dist/commands/liberica/supplier-contacts/update.js.map +1 -0
- package/dist/core/api/client.d.ts +63 -0
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +1050 -65
- package/dist/core/api/client.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/calendar.d.ts +28 -0
- package/dist/types/calendar.d.ts.map +1 -0
- package/dist/types/calendar.js +2 -0
- package/dist/types/calendar.js.map +1 -0
- package/dist/types/client-contact.d.ts +65 -0
- package/dist/types/client-contact.d.ts.map +1 -0
- package/dist/types/client-contact.js +4 -0
- package/dist/types/client-contact.js.map +1 -0
- package/dist/types/dict.d.ts +97 -0
- package/dist/types/dict.d.ts.map +1 -0
- package/dist/types/dict.js +2 -0
- package/dist/types/dict.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/material.d.ts +1 -1
- package/dist/types/material.d.ts.map +1 -1
- package/dist/types/mould-stock-in.d.ts +70 -0
- package/dist/types/mould-stock-in.d.ts.map +1 -0
- package/dist/types/mould-stock-in.js +3 -0
- package/dist/types/mould-stock-in.js.map +1 -0
- package/dist/types/mould.d.ts +61 -0
- package/dist/types/mould.d.ts.map +1 -0
- package/dist/types/mould.js +2 -0
- package/dist/types/mould.js.map +1 -0
- package/dist/types/operation.d.ts +66 -0
- package/dist/types/operation.d.ts.map +1 -0
- package/dist/types/operation.js +2 -0
- package/dist/types/operation.js.map +1 -0
- package/dist/types/stock.d.ts +133 -0
- package/dist/types/stock.d.ts.map +1 -0
- package/dist/types/stock.js +3 -0
- package/dist/types/stock.js.map +1 -0
- package/dist/types/supplier-contact.d.ts +65 -0
- package/dist/types/supplier-contact.d.ts.map +1 -0
- package/dist/types/supplier-contact.js +4 -0
- package/dist/types/supplier-contact.js.map +1 -0
- package/docs/commands/REFERENCE.md +24 -4
- package/docs/commands/liberica/calendar/DESIGN.md +333 -0
- package/docs/commands/liberica/client-contacts/create.md +152 -0
- package/docs/commands/liberica/client-contacts/delete.md +123 -0
- package/docs/commands/liberica/client-contacts/get.md +133 -0
- package/docs/commands/liberica/client-contacts/list.md +143 -0
- package/docs/commands/liberica/client-contacts/update.md +158 -0
- package/docs/commands/liberica/stock/ledger.md +209 -0
- package/docs/commands/liberica/stock/list.md +165 -0
- package/docs/commands/liberica/supplier-contacts/create.md +152 -0
- package/docs/commands/liberica/supplier-contacts/delete.md +123 -0
- package/docs/commands/liberica/supplier-contacts/get.md +133 -0
- package/docs/commands/liberica/supplier-contacts/list.md +143 -0
- package/docs/commands/liberica/supplier-contacts/update.md +158 -0
- package/package.json +1 -1
- package/src/commands/liberica/calendar/index.ts +13 -0
- package/src/commands/liberica/calendar/list.ts +214 -0
- package/src/commands/liberica/calendar/set.ts +130 -0
- package/src/commands/liberica/client-contacts/create.ts +115 -0
- package/src/commands/liberica/client-contacts/delete.ts +140 -0
- package/src/commands/liberica/client-contacts/get.ts +103 -0
- package/src/commands/liberica/client-contacts/index.ts +19 -0
- package/src/commands/liberica/client-contacts/list.ts +118 -0
- package/src/commands/liberica/client-contacts/update.ts +137 -0
- package/src/commands/liberica/dict-types/get.ts +74 -0
- package/src/commands/liberica/dict-types/index.ts +15 -0
- package/src/commands/liberica/dict-types/list.ts +118 -0
- package/src/commands/liberica/dict-types/update.ts +134 -0
- package/src/commands/liberica/dicts/create.ts +175 -0
- package/src/commands/liberica/dicts/delete.ts +107 -0
- package/src/commands/liberica/dicts/get.ts +80 -0
- package/src/commands/liberica/dicts/index.ts +19 -0
- package/src/commands/liberica/dicts/list.ts +114 -0
- package/src/commands/liberica/dicts/update.ts +116 -0
- package/src/commands/liberica/index.ts +20 -0
- package/src/commands/liberica/materials/create.ts +13 -5
- package/src/commands/liberica/materials/update.ts +1 -1
- package/src/commands/liberica/mould/get.ts +111 -0
- package/src/commands/liberica/mould/index.ts +17 -0
- package/src/commands/liberica/mould/list.ts +157 -0
- package/src/commands/liberica/mould/set-status.ts +99 -0
- package/src/commands/liberica/mould/stock-in.ts +165 -0
- package/src/commands/liberica/operations/active.ts +153 -0
- package/src/commands/liberica/operations/batch-delete.ts +131 -0
- package/src/commands/liberica/operations/copy.ts +138 -0
- package/src/commands/liberica/operations/create.ts +223 -0
- package/src/commands/liberica/operations/deactive.ts +152 -0
- package/src/commands/liberica/operations/delete.ts +128 -0
- package/src/commands/liberica/operations/design.md +587 -0
- package/src/commands/liberica/operations/get.ts +112 -0
- package/src/commands/liberica/operations/index.ts +27 -0
- package/src/commands/liberica/operations/list.ts +180 -0
- package/src/commands/liberica/operations/update.ts +218 -0
- package/src/commands/liberica/stock/index.ts +13 -0
- package/src/commands/liberica/stock/ledger.ts +159 -0
- package/src/commands/liberica/stock/list.ts +128 -0
- package/src/commands/liberica/supplier-contacts/create.ts +120 -0
- package/src/commands/liberica/supplier-contacts/delete.ts +88 -0
- package/src/commands/liberica/supplier-contacts/get.ts +94 -0
- package/src/commands/liberica/supplier-contacts/index.ts +19 -0
- package/src/commands/liberica/supplier-contacts/list.ts +130 -0
- package/src/commands/liberica/supplier-contacts/update.ts +127 -0
- package/src/core/api/client.ts +1238 -17
- package/src/index.ts +1 -1
- package/src/types/calendar.ts +36 -0
- package/src/types/client-contact.ts +78 -0
- package/src/types/dict.ts +121 -0
- package/src/types/index.ts +7 -0
- package/src/types/material.ts +1 -1
- package/src/types/mould-stock-in.ts +82 -0
- package/src/types/mould.ts +74 -0
- package/src/types/operation.ts +72 -0
- package/src/types/stock.ts +161 -0
- package/src/types/supplier-contact.ts +78 -0
|
@@ -0,0 +1,115 @@
|
|
|
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 { CreateClientContactRequest } from '../../../types/client-contact.js';
|
|
6
|
+
|
|
7
|
+
export function createClientContactCreateCommand(): Command {
|
|
8
|
+
const cmd = new Command('create');
|
|
9
|
+
cmd.description('Create a new client contact');
|
|
10
|
+
|
|
11
|
+
cmd
|
|
12
|
+
.requiredOption('-c, --client-id <string>', 'Client ID (required)')
|
|
13
|
+
.requiredOption('-n, --name <string>', 'Contact name (required)')
|
|
14
|
+
.option('-p, --phone <string>', 'Mobile phone')
|
|
15
|
+
.option('-t, --telephone <string>', 'Telephone')
|
|
16
|
+
.option('-e, --email <string>', 'Email')
|
|
17
|
+
.option('-s, --sex <string>', 'Sex')
|
|
18
|
+
.option('-b, --birthday <string>', 'Birthday (YYYY-MM-DD)')
|
|
19
|
+
.option('-q, --qq <string>', 'QQ number')
|
|
20
|
+
.option('-w, --wechat <string>', 'WeChat ID')
|
|
21
|
+
.option('-a, --address <string>', 'Address')
|
|
22
|
+
.option('-d, --default', 'Set as default contact')
|
|
23
|
+
.option('-r, --remark <string>', 'Remark')
|
|
24
|
+
.option('--dry-run', 'Preview the operation without executing')
|
|
25
|
+
.option('--json', 'Output as JSON')
|
|
26
|
+
.action(async (options: Record<string, unknown>) => {
|
|
27
|
+
const context = configManager.getCurrentContext();
|
|
28
|
+
const environment = context.environment;
|
|
29
|
+
const tenant = context.tenant;
|
|
30
|
+
const jsonOutput = options.json === true;
|
|
31
|
+
|
|
32
|
+
const clientId = options.clientId as string;
|
|
33
|
+
const clientContactName = options.name as string;
|
|
34
|
+
|
|
35
|
+
const data: CreateClientContactRequest = {
|
|
36
|
+
clientId,
|
|
37
|
+
clientContactName,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (options.phone) data.clientContactPhone = options.phone as string;
|
|
41
|
+
if (options.telephone) data.clientContactTelephone = options.telephone as string;
|
|
42
|
+
if (options.email) data.clientContactEmail = options.email as string;
|
|
43
|
+
if (options.sex) data.clientContactSex = options.sex as string;
|
|
44
|
+
if (options.birthday) data.clientContactBirthday = options.birthday as string;
|
|
45
|
+
if (options.qq) data.clientContactQq = options.qq as string;
|
|
46
|
+
if (options.wechat) data.clientContactWechat = options.wechat as string;
|
|
47
|
+
if (options.address) data.clientContactAddress = options.address as string;
|
|
48
|
+
if (options.default) data.defaultFlag = 'Y';
|
|
49
|
+
if (options.remark) data.remark = options.remark as string;
|
|
50
|
+
|
|
51
|
+
if (options.dryRun) {
|
|
52
|
+
if (jsonOutput) {
|
|
53
|
+
console.log(JSON.stringify({ success: true, dryRun: true, data }));
|
|
54
|
+
} else {
|
|
55
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual API call will be made\n'));
|
|
56
|
+
console.log(chalk.gray(' This operation will create the following client contact:'));
|
|
57
|
+
console.log(` ${chalk.gray('Client ID:')} ${clientId}`);
|
|
58
|
+
console.log(` ${chalk.gray('Name:')} ${clientContactName}`);
|
|
59
|
+
if (data.clientContactPhone) console.log(` ${chalk.gray('Phone:')} ${data.clientContactPhone}`);
|
|
60
|
+
if (data.clientContactTelephone) console.log(` ${chalk.gray('Telephone:')} ${data.clientContactTelephone}`);
|
|
61
|
+
if (data.clientContactEmail) console.log(` ${chalk.gray('Email:')} ${data.clientContactEmail}`);
|
|
62
|
+
if (data.clientContactSex) console.log(` ${chalk.gray('Sex:')} ${data.clientContactSex}`);
|
|
63
|
+
if (data.clientContactBirthday) console.log(` ${chalk.gray('Birthday:')} ${data.clientContactBirthday}`);
|
|
64
|
+
if (data.clientContactQq) console.log(` ${chalk.gray('QQ:')} ${data.clientContactQq}`);
|
|
65
|
+
if (data.clientContactWechat) console.log(` ${chalk.gray('WeChat:')} ${data.clientContactWechat}`);
|
|
66
|
+
if (data.clientContactAddress) console.log(` ${chalk.gray('Address:')} ${data.clientContactAddress}`);
|
|
67
|
+
if (data.defaultFlag) console.log(` ${chalk.gray('Default:')} ${data.defaultFlag}`);
|
|
68
|
+
if (data.remark) console.log(` ${chalk.gray('Remark:')} ${data.remark}`);
|
|
69
|
+
console.log();
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const response = await apiClient.createClientContact(environment, tenant, data);
|
|
76
|
+
|
|
77
|
+
if (response.success) {
|
|
78
|
+
if (jsonOutput) {
|
|
79
|
+
console.log(JSON.stringify({ success: true, data: response.data }));
|
|
80
|
+
} else {
|
|
81
|
+
console.log(chalk.green('\n✓ Client contact created successfully\n'));
|
|
82
|
+
if (response.data && typeof response.data === 'object' && 'clientContactId' in response.data) {
|
|
83
|
+
console.log(` ${chalk.gray('Contact ID:')} ${chalk.green(String((response.data as { clientContactId: string }).clientContactId))}`);
|
|
84
|
+
}
|
|
85
|
+
console.log(` ${chalk.gray('Client ID:')} ${clientId}`);
|
|
86
|
+
console.log(` ${chalk.gray('Name:')} ${clientContactName}`);
|
|
87
|
+
console.log();
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
const errorMsg = response.error?.message || 'Failed to create client contact';
|
|
91
|
+
const errorCode = response.error?.code || 'CREATE_CLIENT_CONTACT_ERROR';
|
|
92
|
+
if (jsonOutput) {
|
|
93
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
94
|
+
} else {
|
|
95
|
+
console.error(chalk.red(`\n✗ Failed to create client contact: ${errorMsg}`));
|
|
96
|
+
if (response.error?.code) {
|
|
97
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
98
|
+
}
|
|
99
|
+
console.error();
|
|
100
|
+
}
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
105
|
+
if (jsonOutput) {
|
|
106
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
107
|
+
} else {
|
|
108
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
109
|
+
}
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return cmd;
|
|
115
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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 { ClientContact } from '../../../types/client-contact.js';
|
|
7
|
+
|
|
8
|
+
export function createClientContactDeleteCommand(): Command {
|
|
9
|
+
const cmd = new Command('delete');
|
|
10
|
+
cmd.description('Delete a client contact');
|
|
11
|
+
|
|
12
|
+
cmd
|
|
13
|
+
.arguments('<contact-id>')
|
|
14
|
+
.option('--force', 'Skip confirmation and actually delete')
|
|
15
|
+
.option('--dry-run', 'Preview the operation (default)')
|
|
16
|
+
.option('--json', 'Output as JSON')
|
|
17
|
+
.action(async (contactId: 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 (!contactId || contactId.trim() === '') {
|
|
24
|
+
if (jsonOutput) {
|
|
25
|
+
console.log(JSON.stringify({ success: false, error: { code: 'VALIDATION_ERROR', message: 'contact-id is required' } }));
|
|
26
|
+
} else {
|
|
27
|
+
console.error(chalk.red('\n✗ Contact ID is required\n'));
|
|
28
|
+
}
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!jsonOutput) {
|
|
33
|
+
console.log(chalk.bold(`\n🗑️ Delete Client Contact (${environment})\n`));
|
|
34
|
+
console.log(chalk.gray(` Contact ID: ${contactId}`));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let contact: ClientContact | undefined;
|
|
38
|
+
try {
|
|
39
|
+
const contactResponse = await apiClient.getClientContact(environment, tenant, contactId);
|
|
40
|
+
if (!contactResponse.success || !contactResponse.data) {
|
|
41
|
+
const errMsg = `Client contact not found: ${contactId}`;
|
|
42
|
+
if (jsonOutput) {
|
|
43
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
44
|
+
} else {
|
|
45
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
46
|
+
}
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
contact = contactResponse.data as ClientContact;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
52
|
+
if (jsonOutput) {
|
|
53
|
+
console.log(JSON.stringify({ success: false, error: { code: 'FETCH_ERROR', message: `Failed to fetch client contact: ${errMsg}` } }));
|
|
54
|
+
} else {
|
|
55
|
+
console.error(chalk.red(`\n✗ Failed to fetch client contact: ${errMsg}\n`));
|
|
56
|
+
}
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!jsonOutput && contact) {
|
|
61
|
+
console.log(chalk.gray(` Name: ${contact.clientContactName}`));
|
|
62
|
+
console.log(chalk.gray(` Client ID: ${contact.clientId}`));
|
|
63
|
+
if (contact.clientContactPhone) {
|
|
64
|
+
console.log(chalk.gray(` Phone: ${contact.clientContactPhone}`));
|
|
65
|
+
}
|
|
66
|
+
if (contact.clientContactEmail) {
|
|
67
|
+
console.log(chalk.gray(` Email: ${contact.clientContactEmail}`));
|
|
68
|
+
}
|
|
69
|
+
if (contact.defaultFlag === 'Y') {
|
|
70
|
+
console.log(chalk.gray(` Default: Yes`));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const isDryRun = !options.force;
|
|
75
|
+
|
|
76
|
+
if (isDryRun) {
|
|
77
|
+
if (jsonOutput) {
|
|
78
|
+
console.log(JSON.stringify({
|
|
79
|
+
success: true,
|
|
80
|
+
dryRun: true,
|
|
81
|
+
message: 'Dry-Run Mode: No actual API call will be made',
|
|
82
|
+
data: { clientContactId: contactId, contact }
|
|
83
|
+
}));
|
|
84
|
+
} else {
|
|
85
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual API call will be made\n'));
|
|
86
|
+
console.log(chalk.yellow(' ⚠️ Add --force option to confirm deletion'));
|
|
87
|
+
console.log();
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const response = await apiClient.deleteClientContact(environment, tenant, contactId);
|
|
94
|
+
|
|
95
|
+
if (response.success) {
|
|
96
|
+
if (jsonOutput) {
|
|
97
|
+
console.log(JSON.stringify({ success: true, data: { clientContactId: contactId, contactName: contact.clientContactName } }));
|
|
98
|
+
} else {
|
|
99
|
+
console.log(chalk.green('\n✓ Client contact deleted successfully\n'));
|
|
100
|
+
console.log(` ${chalk.gray('Contact ID:')} ${chalk.green(contactId)}`);
|
|
101
|
+
console.log(` ${chalk.gray('Name:')} ${chalk.green(contact.clientContactName)}`);
|
|
102
|
+
console.log();
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
const errorMsg = response.error?.message || 'Failed to delete client contact';
|
|
106
|
+
const errorCode = response.error?.code || 'DELETE_ERROR';
|
|
107
|
+
|
|
108
|
+
// Handle "not found" error (should not happen since we already fetched)
|
|
109
|
+
if (errorCode === '01001207001' || errorMsg.includes('不存在')) {
|
|
110
|
+
if (jsonOutput) {
|
|
111
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: `Client contact not found: ${contactId}` } }));
|
|
112
|
+
} else {
|
|
113
|
+
console.error(chalk.red(`\n✗ Client contact not found: ${contactId}\n`));
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
if (jsonOutput) {
|
|
117
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
118
|
+
} else {
|
|
119
|
+
console.error(chalk.red(`\n✗ Failed to delete client contact: ${errorMsg}`));
|
|
120
|
+
if (response.error?.code) {
|
|
121
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
122
|
+
}
|
|
123
|
+
console.error();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
130
|
+
if (jsonOutput) {
|
|
131
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
132
|
+
} else {
|
|
133
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
134
|
+
}
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return cmd;
|
|
140
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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 { ClientContact } from '../../../types/client-contact.js';
|
|
7
|
+
|
|
8
|
+
export function createClientContactGetCommand(): Command {
|
|
9
|
+
const getCommand = new Command('get');
|
|
10
|
+
getCommand.description('Get client contact details by ID');
|
|
11
|
+
getCommand.arguments('<contact-id>');
|
|
12
|
+
getCommand.option('--json', 'Output as JSON');
|
|
13
|
+
|
|
14
|
+
getCommand.action(async (id: string, options: Record<string, unknown>) => {
|
|
15
|
+
const context = configManager.getCurrentContext();
|
|
16
|
+
const environment = (options.env as Environment) || context.environment;
|
|
17
|
+
const tenant = (options.tenant as string) || context.tenant;
|
|
18
|
+
|
|
19
|
+
if (!id) {
|
|
20
|
+
console.error(chalk.red('\n✗ Client contact ID is required\n'));
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const clientContactId = id;
|
|
25
|
+
if (!clientContactId || clientContactId.trim() === '') {
|
|
26
|
+
console.error(chalk.red('\n✗ Invalid client contact ID.\n'));
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const response = await apiClient.getClientContact(environment, tenant, clientContactId);
|
|
32
|
+
|
|
33
|
+
if (!response.success) {
|
|
34
|
+
const errorCode = response.error?.code || 'UNKNOWN_ERROR';
|
|
35
|
+
const errorMessage = response.error?.message || 'Unknown error';
|
|
36
|
+
|
|
37
|
+
if (errorCode === '01001207001' || errorMessage.includes('不存在')) {
|
|
38
|
+
console.error(chalk.red(`\n✗ Client contact not found: ${clientContactId}\n`));
|
|
39
|
+
} else {
|
|
40
|
+
console.error(chalk.red(`\n✗ Error: ${errorMessage} (${errorCode})\n`));
|
|
41
|
+
}
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const contact = response.data as ClientContact | null;
|
|
46
|
+
|
|
47
|
+
if (!contact) {
|
|
48
|
+
console.error(chalk.red('\n✗ Client contact not found\n'));
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (options.json) {
|
|
53
|
+
console.log(JSON.stringify({
|
|
54
|
+
success: true,
|
|
55
|
+
data: contact,
|
|
56
|
+
}, null, 2));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(chalk.bold('\n📇 Client Contact Details\n'));
|
|
61
|
+
console.log(` ${chalk.gray('Contact ID:')} ${contact.clientContactId}`);
|
|
62
|
+
console.log(` ${chalk.gray('Client ID:')} ${contact.clientId}`);
|
|
63
|
+
console.log(` ${chalk.gray('Name:')} ${contact.clientContactName}`);
|
|
64
|
+
if (contact.clientContactPhone) {
|
|
65
|
+
console.log(` ${chalk.gray('Phone:')} ${contact.clientContactPhone}`);
|
|
66
|
+
}
|
|
67
|
+
if (contact.clientContactTelephone) {
|
|
68
|
+
console.log(` ${chalk.gray('Telephone:')} ${contact.clientContactTelephone}`);
|
|
69
|
+
}
|
|
70
|
+
if (contact.clientContactEmail) {
|
|
71
|
+
console.log(` ${chalk.gray('Email:')} ${contact.clientContactEmail}`);
|
|
72
|
+
}
|
|
73
|
+
if (contact.clientContactSex) {
|
|
74
|
+
console.log(` ${chalk.gray('Sex:')} ${contact.clientContactSex}`);
|
|
75
|
+
}
|
|
76
|
+
if (contact.clientContactBirthday) {
|
|
77
|
+
console.log(` ${chalk.gray('Birthday:')} ${contact.clientContactBirthday}`);
|
|
78
|
+
}
|
|
79
|
+
if (contact.clientContactQq) {
|
|
80
|
+
console.log(` ${chalk.gray('QQ:')} ${contact.clientContactQq}`);
|
|
81
|
+
}
|
|
82
|
+
if (contact.clientContactWechat) {
|
|
83
|
+
console.log(` ${chalk.gray('WeChat:')} ${contact.clientContactWechat}`);
|
|
84
|
+
}
|
|
85
|
+
if (contact.clientContactAddress) {
|
|
86
|
+
console.log(` ${chalk.gray('Address:')} ${contact.clientContactAddress}`);
|
|
87
|
+
}
|
|
88
|
+
if (contact.defaultFlag) {
|
|
89
|
+
const defaultText = contact.defaultFlag === 'Y' ? chalk.green('Yes') : chalk.gray('No');
|
|
90
|
+
console.log(` ${chalk.gray('Default:')} ${defaultText}`);
|
|
91
|
+
}
|
|
92
|
+
if (contact.remark) {
|
|
93
|
+
console.log(` ${chalk.gray('Remark:')} ${contact.remark}`);
|
|
94
|
+
}
|
|
95
|
+
console.log();
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(chalk.red(`\n✗ Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return getCommand;
|
|
103
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { createClientContactListCommand } from './list.js';
|
|
3
|
+
import { createClientContactGetCommand } from './get.js';
|
|
4
|
+
import { createClientContactCreateCommand } from './create.js';
|
|
5
|
+
import { createClientContactUpdateCommand } from './update.js';
|
|
6
|
+
import { createClientContactDeleteCommand } from './delete.js';
|
|
7
|
+
|
|
8
|
+
export function createClientContactsCommand(): Command {
|
|
9
|
+
const clientContactsCommand = new Command('client-contacts');
|
|
10
|
+
clientContactsCommand.description('Manage client contacts');
|
|
11
|
+
|
|
12
|
+
clientContactsCommand.addCommand(createClientContactListCommand());
|
|
13
|
+
clientContactsCommand.addCommand(createClientContactGetCommand());
|
|
14
|
+
clientContactsCommand.addCommand(createClientContactCreateCommand());
|
|
15
|
+
clientContactsCommand.addCommand(createClientContactUpdateCommand());
|
|
16
|
+
clientContactsCommand.addCommand(createClientContactDeleteCommand());
|
|
17
|
+
|
|
18
|
+
return clientContactsCommand;
|
|
19
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import Table from 'cli-table3';
|
|
4
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
5
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
6
|
+
import { ClientContactListResponse } from '../../../types/client-contact.js';
|
|
7
|
+
import { Environment } from '../../../types/index.js';
|
|
8
|
+
|
|
9
|
+
export function createClientContactListCommand(): Command {
|
|
10
|
+
const listCommand = new Command('list');
|
|
11
|
+
listCommand.description('List client contacts with pagination');
|
|
12
|
+
|
|
13
|
+
listCommand
|
|
14
|
+
.requiredOption('-c, --client-id <string>', 'Client ID (required)')
|
|
15
|
+
.option('-p, --page <number>', 'Page number', '1')
|
|
16
|
+
.option('-s, --size <number>', 'Page size', '20')
|
|
17
|
+
.option('--json', 'Output as JSON')
|
|
18
|
+
.action(async (options) => {
|
|
19
|
+
const context = configManager.getCurrentContext();
|
|
20
|
+
const environment = (options.env as Environment) || context.environment;
|
|
21
|
+
const tenant = options.tenant || context.tenant;
|
|
22
|
+
|
|
23
|
+
const page = parseInt(options.page as string, 10) - 1; // API uses 0-based pagination
|
|
24
|
+
const size = parseInt(options.size as string, 10);
|
|
25
|
+
|
|
26
|
+
const params = {
|
|
27
|
+
clientId: options.clientId as string,
|
|
28
|
+
pageNo: page,
|
|
29
|
+
pageSize: size,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const response = await apiClient.listClientContacts(environment, tenant, params);
|
|
33
|
+
|
|
34
|
+
if (!response.success) {
|
|
35
|
+
console.error(chalk.red(`\n✗ Failed to list client contacts: ${response.error?.message || 'Unknown error'}`));
|
|
36
|
+
if (response.error?.code) {
|
|
37
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
38
|
+
}
|
|
39
|
+
console.error();
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const data = response.data as ClientContactListResponse | null;
|
|
44
|
+
|
|
45
|
+
if (!data) {
|
|
46
|
+
if (options.json) {
|
|
47
|
+
console.log(JSON.stringify({ success: true, data: { items: [], pagination: { pageNo: 0, pageSize: 20, totalRows: 0 } } }, null, 2));
|
|
48
|
+
} else {
|
|
49
|
+
console.log(chalk.bold('\n📋 Client Contact List\n'));
|
|
50
|
+
console.log(chalk.gray(' No client contacts found\n'));
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (options.json) {
|
|
56
|
+
console.log(
|
|
57
|
+
JSON.stringify(
|
|
58
|
+
{
|
|
59
|
+
success: true,
|
|
60
|
+
data: {
|
|
61
|
+
items: data.rows || [],
|
|
62
|
+
pagination: {
|
|
63
|
+
pageNo: data.pageNo,
|
|
64
|
+
pageSize: data.pageSize,
|
|
65
|
+
totalRows: data.totalRows,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
null,
|
|
70
|
+
2
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const records = data.rows || [];
|
|
77
|
+
|
|
78
|
+
if (records.length === 0) {
|
|
79
|
+
console.log(chalk.bold('\n📋 Client Contact List\n'));
|
|
80
|
+
console.log(chalk.gray(' No client contacts found\n'));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
console.log(chalk.bold('\n📋 Client Contact List\n'));
|
|
85
|
+
|
|
86
|
+
const table = new Table({
|
|
87
|
+
head: [chalk.bold('ID'), chalk.bold('NAME'), chalk.bold('PHONE'), chalk.bold('TELEPHONE'), chalk.bold('EMAIL'), chalk.bold('DEFAULT')],
|
|
88
|
+
colWidths: [10, 15, 15, 15, 25, 10],
|
|
89
|
+
style: {
|
|
90
|
+
head: [],
|
|
91
|
+
border: [],
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
for (const contact of records) {
|
|
96
|
+
const defaultText = contact.defaultFlag === 'Y' ? chalk.green('Y') : chalk.gray('N');
|
|
97
|
+
table.push([
|
|
98
|
+
contact.clientContactId,
|
|
99
|
+
contact.clientContactName || '-',
|
|
100
|
+
contact.clientContactPhone || '-',
|
|
101
|
+
contact.clientContactTelephone || '-',
|
|
102
|
+
contact.clientContactEmail || '-',
|
|
103
|
+
defaultText,
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log(table.toString());
|
|
108
|
+
console.log();
|
|
109
|
+
console.log(
|
|
110
|
+
chalk.gray(
|
|
111
|
+
` Total: ${data.totalRows} | Page: ${data.pageNo + 1} / ${Math.ceil(data.totalRows / data.pageSize) || 1} | Size: ${data.pageSize}`
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
console.log();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return listCommand;
|
|
118
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
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 { UpdateClientContactRequest } from '../../../types/client-contact.js';
|
|
7
|
+
|
|
8
|
+
export function createClientContactUpdateCommand(): Command {
|
|
9
|
+
const cmd = new Command('update');
|
|
10
|
+
cmd.description('Update a client contact');
|
|
11
|
+
cmd.arguments('<contact-id>');
|
|
12
|
+
|
|
13
|
+
cmd
|
|
14
|
+
.option('-n, --name <string>', 'Contact name')
|
|
15
|
+
.option('-p, --phone <string>', 'Mobile phone')
|
|
16
|
+
.option('-t, --telephone <string>', 'Telephone')
|
|
17
|
+
.option('-e, --email <string>', 'Email')
|
|
18
|
+
.option('-s, --sex <string>', 'Sex')
|
|
19
|
+
.option('-b, --birthday <string>', 'Birthday (YYYY-MM-DD)')
|
|
20
|
+
.option('-q, --qq <string>', 'QQ number')
|
|
21
|
+
.option('-w, --wechat <string>', 'WeChat ID')
|
|
22
|
+
.option('-a, --address <string>', 'Address')
|
|
23
|
+
.option('-d, --default', 'Set as default contact')
|
|
24
|
+
.option('-r, --remark <string>', 'Remark')
|
|
25
|
+
.option('--dry-run', 'Preview the operation without executing')
|
|
26
|
+
.option('--json', 'Output as JSON')
|
|
27
|
+
.action(async (contactId: string, options: Record<string, unknown>) => {
|
|
28
|
+
const context = configManager.getCurrentContext();
|
|
29
|
+
const environment = context.environment as Environment;
|
|
30
|
+
const tenant = context.tenant;
|
|
31
|
+
const jsonOutput = options.json === true;
|
|
32
|
+
|
|
33
|
+
if (!contactId) {
|
|
34
|
+
if (jsonOutput) {
|
|
35
|
+
console.log(JSON.stringify({ success: false, error: { code: 'VALIDATION_ERROR', message: 'Contact ID is required' } }));
|
|
36
|
+
} else {
|
|
37
|
+
console.error(chalk.red('\n✗ Contact ID is required\n'));
|
|
38
|
+
}
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const fields: Partial<UpdateClientContactRequest> = {
|
|
43
|
+
clientContactId: contactId,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (options.name) fields.clientContactName = options.name as string;
|
|
47
|
+
if (options.phone) fields.clientContactPhone = options.phone as string;
|
|
48
|
+
if (options.telephone) fields.clientContactTelephone = options.telephone as string;
|
|
49
|
+
if (options.email) fields.clientContactEmail = options.email as string;
|
|
50
|
+
if (options.sex) fields.clientContactSex = options.sex as string;
|
|
51
|
+
if (options.birthday) fields.clientContactBirthday = options.birthday as string;
|
|
52
|
+
if (options.qq) fields.clientContactQq = options.qq as string;
|
|
53
|
+
if (options.wechat) fields.clientContactWechat = options.wechat as string;
|
|
54
|
+
if (options.address) fields.clientContactAddress = options.address as string;
|
|
55
|
+
if (options.default) fields.defaultFlag = 'Y';
|
|
56
|
+
if (options.remark) fields.remark = options.remark as string;
|
|
57
|
+
|
|
58
|
+
const updateFields = Object.keys(fields).filter(k => k !== 'clientContactId' && fields[k as keyof UpdateClientContactRequest] !== undefined);
|
|
59
|
+
if (updateFields.length === 0) {
|
|
60
|
+
if (jsonOutput) {
|
|
61
|
+
console.log(JSON.stringify({ success: false, error: { code: 'VALIDATION_ERROR', message: 'No fields to update. Provide at least one of: --name, --phone, --telephone, --email, --sex, --birthday, --qq, --wechat, --address, --default, --remark' } }));
|
|
62
|
+
} else {
|
|
63
|
+
console.error(chalk.red('\n✗ No fields to update. Provide at least one of: --name, --phone, --telephone, --email, --sex, --birthday, --qq, --wechat, --address, --default, --remark\n'));
|
|
64
|
+
}
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const updateData: UpdateClientContactRequest = fields as UpdateClientContactRequest;
|
|
69
|
+
|
|
70
|
+
if (options.dryRun) {
|
|
71
|
+
if (jsonOutput) {
|
|
72
|
+
console.log(JSON.stringify({ success: true, dryRun: true, data: updateData }));
|
|
73
|
+
} else {
|
|
74
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual API call will be made\n'));
|
|
75
|
+
console.log(chalk.gray(' This operation will update the client contact with the following fields:'));
|
|
76
|
+
console.log(` ${chalk.gray('Contact ID:')} ${contactId}`);
|
|
77
|
+
if (fields.clientContactName) console.log(` ${chalk.gray('Name:')} ${fields.clientContactName}`);
|
|
78
|
+
if (fields.clientContactPhone) console.log(` ${chalk.gray('Phone:')} ${fields.clientContactPhone}`);
|
|
79
|
+
if (fields.clientContactTelephone) console.log(` ${chalk.gray('Telephone:')} ${fields.clientContactTelephone}`);
|
|
80
|
+
if (fields.clientContactEmail) console.log(` ${chalk.gray('Email:')} ${fields.clientContactEmail}`);
|
|
81
|
+
if (fields.clientContactSex) console.log(` ${chalk.gray('Sex:')} ${fields.clientContactSex}`);
|
|
82
|
+
if (fields.clientContactBirthday) console.log(` ${chalk.gray('Birthday:')} ${fields.clientContactBirthday}`);
|
|
83
|
+
if (fields.clientContactQq) console.log(` ${chalk.gray('QQ:')} ${fields.clientContactQq}`);
|
|
84
|
+
if (fields.clientContactWechat) console.log(` ${chalk.gray('WeChat:')} ${fields.clientContactWechat}`);
|
|
85
|
+
if (fields.clientContactAddress) console.log(` ${chalk.gray('Address:')} ${fields.clientContactAddress}`);
|
|
86
|
+
if (fields.defaultFlag) console.log(` ${chalk.gray('Default:')} ${fields.defaultFlag}`);
|
|
87
|
+
if (fields.remark) console.log(` ${chalk.gray('Remark:')} ${fields.remark}`);
|
|
88
|
+
console.log();
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const response = await apiClient.updateClientContact(environment, tenant, updateData);
|
|
95
|
+
|
|
96
|
+
if (response.success) {
|
|
97
|
+
if (jsonOutput) {
|
|
98
|
+
console.log(JSON.stringify({ success: true, data: response.data }));
|
|
99
|
+
} else {
|
|
100
|
+
console.log(chalk.green('\n✓ Client contact updated successfully\n'));
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
104
|
+
const errorCode = response.error?.code || 'UPDATE_CLIENT_CONTACT_ERROR';
|
|
105
|
+
|
|
106
|
+
if (errorCode === '01001207001' || errorMsg.includes('不存在')) {
|
|
107
|
+
if (jsonOutput) {
|
|
108
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: `Client contact not found: ${contactId}` } }));
|
|
109
|
+
} else {
|
|
110
|
+
console.error(chalk.red(`\n✗ Client contact not found: ${contactId}\n`));
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
if (jsonOutput) {
|
|
114
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
115
|
+
} else {
|
|
116
|
+
console.error(chalk.red(`\n✗ Failed to update client contact: ${errorMsg}`));
|
|
117
|
+
if (response.error?.code) {
|
|
118
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
119
|
+
}
|
|
120
|
+
console.error();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
127
|
+
if (jsonOutput) {
|
|
128
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
129
|
+
} else {
|
|
130
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
131
|
+
}
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return cmd;
|
|
137
|
+
}
|