@newpeak/barista-cli 0.1.11 → 0.1.12
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/index.js +1 -1
- package/package.json +7 -3
- package/docs/ARCHITECTURE.md +0 -184
- package/docs/COMMANDS.md +0 -352
- package/docs/COMMAND_DESIGN_SPEC.md +0 -840
- package/docs/INTEGRATION_NOTES.md +0 -270
- package/docs/commands/REFERENCE.md +0 -323
- package/docs/commands/arabica/auth/index.md +0 -296
- package/docs/commands/liberica/auth/index.md +0 -133
- package/docs/commands/liberica/calendar/DESIGN.md +0 -333
- package/docs/commands/liberica/client-contacts/create.md +0 -152
- package/docs/commands/liberica/client-contacts/delete.md +0 -123
- package/docs/commands/liberica/client-contacts/get.md +0 -133
- package/docs/commands/liberica/client-contacts/list.md +0 -143
- package/docs/commands/liberica/client-contacts/update.md +0 -158
- package/docs/commands/liberica/context/index.md +0 -60
- package/docs/commands/liberica/currency/create.md +0 -145
- package/docs/commands/liberica/currency/delete.md +0 -121
- package/docs/commands/liberica/currency/disable.md +0 -119
- package/docs/commands/liberica/currency/enable.md +0 -115
- package/docs/commands/liberica/currency/get.md +0 -118
- package/docs/commands/liberica/currency/list.md +0 -149
- package/docs/commands/liberica/currency/update.md +0 -141
- package/docs/commands/liberica/employees/create.md +0 -185
- package/docs/commands/liberica/employees/disable.md +0 -138
- package/docs/commands/liberica/employees/enable.md +0 -137
- package/docs/commands/liberica/employees/get.md +0 -153
- package/docs/commands/liberica/employees/list.md +0 -168
- package/docs/commands/liberica/employees/update.md +0 -180
- package/docs/commands/liberica/locations/create.md +0 -195
- package/docs/commands/liberica/locations/list.md +0 -171
- package/docs/commands/liberica/materials/create.md +0 -293
- package/docs/commands/liberica/materials/delete.md +0 -240
- package/docs/commands/liberica/materials/disable.md +0 -150
- package/docs/commands/liberica/materials/enable.md +0 -146
- package/docs/commands/liberica/materials/get.md +0 -188
- package/docs/commands/liberica/materials/list.md +0 -198
- package/docs/commands/liberica/materials/update.md +0 -250
- package/docs/commands/liberica/orgs/list.md +0 -62
- package/docs/commands/liberica/positions/list.md +0 -61
- package/docs/commands/liberica/roles/list.md +0 -67
- package/docs/commands/liberica/stock/ledger.md +0 -209
- package/docs/commands/liberica/stock/list.md +0 -165
- package/docs/commands/liberica/supplier-contacts/create.md +0 -152
- package/docs/commands/liberica/supplier-contacts/delete.md +0 -123
- package/docs/commands/liberica/supplier-contacts/get.md +0 -133
- package/docs/commands/liberica/supplier-contacts/list.md +0 -143
- package/docs/commands/liberica/supplier-contacts/update.md +0 -158
- package/docs/commands/liberica/teams/issues/close.md +0 -161
- package/docs/commands/liberica/teams/issues/create.md +0 -212
- package/docs/commands/liberica/teams/issues/delete.md +0 -179
- package/docs/commands/liberica/teams/issues/get.md +0 -167
- package/docs/commands/liberica/teams/issues/list.md +0 -182
- package/docs/commands/liberica/teams/issues/tests-design.md +0 -341
- package/docs/commands/liberica/teams/issues/update.md +0 -202
- package/docs/commands/liberica/teams/projects/create.md +0 -174
- package/docs/commands/liberica/teams/projects/delete.md +0 -180
- package/docs/commands/liberica/teams/projects/get.md +0 -150
- package/docs/commands/liberica/teams/projects/list.md +0 -179
- package/docs/commands/liberica/teams/projects/update.md +0 -175
- package/docs/commands/liberica/teams/tasks/create.md +0 -163
- package/docs/commands/liberica/teams/tasks/delete.md +0 -109
- package/docs/commands/liberica/teams/tasks/get.md +0 -121
- package/docs/commands/liberica/teams/tasks/list.md +0 -148
- package/docs/commands/liberica/teams/tasks/update.md +0 -158
- package/docs/commands/liberica/teams/work-logs/create.md +0 -151
- package/docs/commands/liberica/teams/work-logs/delete.md +0 -130
- package/docs/commands/liberica/teams/work-logs/get.md +0 -131
- package/docs/commands/liberica/teams/work-logs/list.md +0 -153
- package/docs/commands/liberica/teams/work-logs/update.md +0 -150
- package/docs/commands/liberica/transfer-in-forms/batch-delete.md +0 -157
- package/docs/commands/liberica/transfer-in-forms/batch-review.md +0 -157
- package/docs/commands/liberica/transfer-in-forms/batch-unreview.md +0 -157
- package/docs/commands/liberica/transfer-in-forms/create.md +0 -220
- package/docs/commands/liberica/transfer-in-forms/get.md +0 -221
- package/docs/commands/liberica/transfer-in-forms/list.md +0 -242
- package/docs/commands/liberica/transfer-in-forms/update.md +0 -185
- package/docs/commands/liberica/transfer-out-forms/batch-delete.md +0 -187
- package/docs/commands/liberica/transfer-out-forms/batch-review.md +0 -157
- package/docs/commands/liberica/transfer-out-forms/batch-unreview.md +0 -157
- package/docs/commands/liberica/transfer-out-forms/create.md +0 -280
- package/docs/commands/liberica/transfer-out-forms/get.md +0 -211
- package/docs/commands/liberica/transfer-out-forms/list.md +0 -233
- package/docs/commands/liberica/transfer-out-forms/update.md +0 -286
- package/docs/commands/liberica/uoms/create.md +0 -136
- package/docs/commands/liberica/uoms/delete.md +0 -119
- package/docs/commands/liberica/uoms/disable.md +0 -117
- package/docs/commands/liberica/uoms/enable.md +0 -115
- package/docs/commands/liberica/uoms/get.md +0 -119
- package/docs/commands/liberica/uoms/list.md +0 -155
- package/docs/commands/liberica/uoms/update.md +0 -148
- package/docs/commands/liberica/users/create.md +0 -170
- package/docs/commands/liberica/users/get.md +0 -151
- package/docs/commands/liberica/users/list.md +0 -175
- package/docs/commands/liberica/warehouses/create.md +0 -222
- package/docs/commands/liberica/warehouses/list.md +0 -184
- package/src/commands/arabica/auth/index.ts +0 -277
- package/src/commands/arabica/auth/login.ts +0 -5
- package/src/commands/arabica/auth/logout.ts +0 -5
- package/src/commands/arabica/auth/register.ts +0 -5
- package/src/commands/arabica/auth/status.ts +0 -5
- package/src/commands/arabica/index.ts +0 -23
- package/src/commands/auth.ts +0 -107
- package/src/commands/context.ts +0 -60
- package/src/commands/liberica/auth/index.ts +0 -176
- package/src/commands/liberica/calendar/index.ts +0 -13
- package/src/commands/liberica/calendar/list.ts +0 -214
- package/src/commands/liberica/calendar/set.ts +0 -130
- package/src/commands/liberica/client-contacts/create.ts +0 -115
- package/src/commands/liberica/client-contacts/delete.ts +0 -140
- package/src/commands/liberica/client-contacts/get.ts +0 -103
- package/src/commands/liberica/client-contacts/index.ts +0 -19
- package/src/commands/liberica/client-contacts/list.ts +0 -118
- package/src/commands/liberica/client-contacts/update.ts +0 -137
- package/src/commands/liberica/clients/create.ts +0 -122
- package/src/commands/liberica/clients/delete.ts +0 -125
- package/src/commands/liberica/clients/get.ts +0 -88
- package/src/commands/liberica/clients/index.ts +0 -19
- package/src/commands/liberica/clients/list.ts +0 -123
- package/src/commands/liberica/clients/update.ts +0 -103
- package/src/commands/liberica/context/index.ts +0 -43
- package/src/commands/liberica/currency/create.ts +0 -183
- package/src/commands/liberica/currency/delete.ts +0 -124
- package/src/commands/liberica/currency/disable.ts +0 -147
- package/src/commands/liberica/currency/enable.ts +0 -128
- package/src/commands/liberica/currency/get.ts +0 -91
- package/src/commands/liberica/currency/index.ts +0 -23
- package/src/commands/liberica/currency/list.ts +0 -140
- package/src/commands/liberica/currency/update.ts +0 -129
- package/src/commands/liberica/dict-types/get.ts +0 -74
- package/src/commands/liberica/dict-types/index.ts +0 -15
- package/src/commands/liberica/dict-types/list.ts +0 -118
- package/src/commands/liberica/dict-types/update.ts +0 -134
- package/src/commands/liberica/dicts/create.ts +0 -175
- package/src/commands/liberica/dicts/delete.ts +0 -107
- package/src/commands/liberica/dicts/get.ts +0 -80
- package/src/commands/liberica/dicts/index.ts +0 -19
- package/src/commands/liberica/dicts/list.ts +0 -114
- package/src/commands/liberica/dicts/update.ts +0 -116
- package/src/commands/liberica/employees/create.ts +0 -275
- package/src/commands/liberica/employees/delete.ts +0 -122
- package/src/commands/liberica/employees/disable.ts +0 -97
- package/src/commands/liberica/employees/enable.ts +0 -97
- package/src/commands/liberica/employees/get.ts +0 -115
- package/src/commands/liberica/employees/index.ts +0 -23
- package/src/commands/liberica/employees/list.ts +0 -131
- package/src/commands/liberica/employees/update.ts +0 -157
- package/src/commands/liberica/index.ts +0 -81
- package/src/commands/liberica/materials/create.ts +0 -199
- package/src/commands/liberica/materials/delete.ts +0 -105
- package/src/commands/liberica/materials/disable.ts +0 -148
- package/src/commands/liberica/materials/enable.ts +0 -129
- package/src/commands/liberica/materials/get.ts +0 -83
- package/src/commands/liberica/materials/index.ts +0 -23
- package/src/commands/liberica/materials/list.ts +0 -142
- package/src/commands/liberica/materials/update.ts +0 -125
- package/src/commands/liberica/mould/get.ts +0 -111
- package/src/commands/liberica/mould/index.ts +0 -17
- package/src/commands/liberica/mould/list.ts +0 -157
- package/src/commands/liberica/mould/set-status.ts +0 -99
- package/src/commands/liberica/mould/stock-in.ts +0 -165
- package/src/commands/liberica/operations/active.ts +0 -153
- package/src/commands/liberica/operations/batch-delete.ts +0 -131
- package/src/commands/liberica/operations/copy.ts +0 -138
- package/src/commands/liberica/operations/create.ts +0 -223
- package/src/commands/liberica/operations/deactive.ts +0 -152
- package/src/commands/liberica/operations/delete.ts +0 -128
- package/src/commands/liberica/operations/design.md +0 -587
- package/src/commands/liberica/operations/get.ts +0 -112
- package/src/commands/liberica/operations/index.ts +0 -27
- package/src/commands/liberica/operations/list.ts +0 -180
- package/src/commands/liberica/operations/update.ts +0 -218
- package/src/commands/liberica/orgs/index.ts +0 -34
- package/src/commands/liberica/positions/index.ts +0 -30
- package/src/commands/liberica/roles/index.ts +0 -59
- package/src/commands/liberica/stock/index.ts +0 -13
- package/src/commands/liberica/stock/ledger.ts +0 -159
- package/src/commands/liberica/stock/list.ts +0 -128
- package/src/commands/liberica/supplier-contacts/create.ts +0 -120
- package/src/commands/liberica/supplier-contacts/delete.ts +0 -88
- package/src/commands/liberica/supplier-contacts/get.ts +0 -94
- package/src/commands/liberica/supplier-contacts/index.ts +0 -19
- package/src/commands/liberica/supplier-contacts/list.ts +0 -130
- package/src/commands/liberica/supplier-contacts/update.ts +0 -127
- package/src/commands/liberica/suppliers/create.ts +0 -149
- package/src/commands/liberica/suppliers/delete.ts +0 -102
- package/src/commands/liberica/suppliers/disable.ts +0 -145
- package/src/commands/liberica/suppliers/enable.ts +0 -126
- package/src/commands/liberica/suppliers/get.ts +0 -86
- package/src/commands/liberica/suppliers/index.ts +0 -23
- package/src/commands/liberica/suppliers/list.ts +0 -134
- package/src/commands/liberica/suppliers/update.ts +0 -128
- package/src/commands/liberica/teams/index.ts +0 -17
- package/src/commands/liberica/teams/issues/close.ts +0 -104
- package/src/commands/liberica/teams/issues/create.ts +0 -254
- package/src/commands/liberica/teams/issues/delete.ts +0 -58
- package/src/commands/liberica/teams/issues/get.ts +0 -78
- package/src/commands/liberica/teams/issues/index.ts +0 -21
- package/src/commands/liberica/teams/issues/list.ts +0 -144
- package/src/commands/liberica/teams/issues/update.ts +0 -141
- package/src/commands/liberica/teams/projects/create.ts +0 -159
- package/src/commands/liberica/teams/projects/delete.ts +0 -58
- package/src/commands/liberica/teams/projects/get.ts +0 -87
- package/src/commands/liberica/teams/projects/index.ts +0 -19
- package/src/commands/liberica/teams/projects/list.ts +0 -147
- package/src/commands/liberica/teams/projects/update.ts +0 -117
- package/src/commands/liberica/teams/tasks/create.ts +0 -102
- package/src/commands/liberica/teams/tasks/delete.ts +0 -92
- package/src/commands/liberica/teams/tasks/get.ts +0 -64
- package/src/commands/liberica/teams/tasks/index.ts +0 -19
- package/src/commands/liberica/teams/tasks/list.ts +0 -102
- package/src/commands/liberica/teams/tasks/update.ts +0 -122
- package/src/commands/liberica/teams/work-logs/create.ts +0 -204
- package/src/commands/liberica/teams/work-logs/delete.ts +0 -58
- package/src/commands/liberica/teams/work-logs/get.ts +0 -87
- package/src/commands/liberica/teams/work-logs/index.ts +0 -19
- package/src/commands/liberica/teams/work-logs/list.ts +0 -141
- package/src/commands/liberica/teams/work-logs/update.ts +0 -120
- package/src/commands/liberica/transfer-in-forms/batch-delete.ts +0 -152
- package/src/commands/liberica/transfer-in-forms/batch-review.ts +0 -151
- package/src/commands/liberica/transfer-in-forms/batch-unreview.ts +0 -152
- package/src/commands/liberica/transfer-in-forms/create.ts +0 -179
- package/src/commands/liberica/transfer-in-forms/get.ts +0 -107
- package/src/commands/liberica/transfer-in-forms/index.ts +0 -23
- package/src/commands/liberica/transfer-in-forms/list.ts +0 -97
- package/src/commands/liberica/transfer-in-forms/update.ts +0 -213
- package/src/commands/liberica/transfer-out-forms/batch-delete.ts +0 -83
- package/src/commands/liberica/transfer-out-forms/batch-review.ts +0 -148
- package/src/commands/liberica/transfer-out-forms/batch-unreview.ts +0 -56
- package/src/commands/liberica/transfer-out-forms/create.ts +0 -194
- package/src/commands/liberica/transfer-out-forms/get.ts +0 -114
- package/src/commands/liberica/transfer-out-forms/index.ts +0 -23
- package/src/commands/liberica/transfer-out-forms/list.ts +0 -125
- package/src/commands/liberica/transfer-out-forms/update.ts +0 -197
- package/src/commands/liberica/uoms/create.ts +0 -134
- package/src/commands/liberica/uoms/delete.ts +0 -105
- package/src/commands/liberica/uoms/disable.ts +0 -148
- package/src/commands/liberica/uoms/enable.ts +0 -129
- package/src/commands/liberica/uoms/get.ts +0 -83
- package/src/commands/liberica/uoms/index.ts +0 -23
- package/src/commands/liberica/uoms/list.ts +0 -129
- package/src/commands/liberica/uoms/update.ts +0 -124
- package/src/commands/liberica/users/create.ts +0 -133
- package/src/commands/liberica/users/delete.ts +0 -49
- package/src/commands/liberica/users/disable.ts +0 -41
- package/src/commands/liberica/users/enable.ts +0 -30
- package/src/commands/liberica/users/get.ts +0 -46
- package/src/commands/liberica/users/index.ts +0 -27
- package/src/commands/liberica/users/list.ts +0 -68
- package/src/commands/liberica/users/me.ts +0 -42
- package/src/commands/liberica/users/reset-password.ts +0 -42
- package/src/commands/liberica/users/update.ts +0 -48
- package/src/commands/liberica/warehouses/create.ts +0 -204
- package/src/commands/liberica/warehouses/delete.ts +0 -112
- package/src/commands/liberica/warehouses/disable.ts +0 -174
- package/src/commands/liberica/warehouses/enable.ts +0 -174
- package/src/commands/liberica/warehouses/get.ts +0 -101
- package/src/commands/liberica/warehouses/index.ts +0 -25
- package/src/commands/liberica/warehouses/list.ts +0 -136
- package/src/commands/liberica/warehouses/locations/create.ts +0 -209
- package/src/commands/liberica/warehouses/locations/delete.ts +0 -116
- package/src/commands/liberica/warehouses/locations/disable.ts +0 -174
- package/src/commands/liberica/warehouses/locations/enable.ts +0 -174
- package/src/commands/liberica/warehouses/locations/get.ts +0 -84
- package/src/commands/liberica/warehouses/locations/index.ts +0 -23
- package/src/commands/liberica/warehouses/locations/list.ts +0 -140
- package/src/commands/liberica/warehouses/locations/update.ts +0 -135
- package/src/commands/liberica/warehouses/update.ts +0 -142
- package/src/core/api/client.ts +0 -4443
- package/src/core/auth/token-manager.ts +0 -183
- package/src/core/config/manager.ts +0 -164
- package/src/index.ts +0 -35
- package/src/types/calendar.ts +0 -36
- package/src/types/client-contact.ts +0 -78
- package/src/types/client.ts +0 -115
- package/src/types/currency.ts +0 -90
- package/src/types/dict.ts +0 -121
- package/src/types/employee.ts +0 -102
- package/src/types/index.ts +0 -93
- package/src/types/location.ts +0 -66
- package/src/types/material.ts +0 -61
- package/src/types/mould-stock-in.ts +0 -82
- package/src/types/mould.ts +0 -74
- package/src/types/operation.ts +0 -72
- package/src/types/org.ts +0 -25
- package/src/types/position.ts +0 -24
- package/src/types/stock.ts +0 -161
- package/src/types/supplier-contact.ts +0 -78
- package/src/types/supplier.ts +0 -66
- package/src/types/team-issue.ts +0 -94
- package/src/types/team-project.ts +0 -74
- package/src/types/team-task.ts +0 -98
- package/src/types/team-work-log.ts +0 -87
- package/src/types/transfer-in-form.ts +0 -265
- package/src/types/transfer-out-form.ts +0 -290
- package/src/types/uom.ts +0 -60
- package/src/types/user.ts +0 -64
- package/src/types/warehouse.ts +0 -82
|
@@ -1,129 +0,0 @@
|
|
|
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 { Uom } from '../../../types/uom.js';
|
|
8
|
-
|
|
9
|
-
export function createUomEnableCommand(): Command {
|
|
10
|
-
const enableCommand = new Command('enable');
|
|
11
|
-
enableCommand
|
|
12
|
-
.description('Enable (activate) a UOM')
|
|
13
|
-
.argument('<uomId>', 'UOM ID')
|
|
14
|
-
.option('--json', 'Output as JSON')
|
|
15
|
-
.action(async (uomId: string, options: Record<string, unknown>) => {
|
|
16
|
-
const context = configManager.getCurrentContext();
|
|
17
|
-
const environment = context.environment as Environment;
|
|
18
|
-
const tenant = context.tenant;
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
(options as any).json = process.argv.includes('--json');
|
|
22
|
-
const jsonOutput = options.json === true;
|
|
23
|
-
|
|
24
|
-
if (!uomId || uomId.trim() === '') {
|
|
25
|
-
const errMsg = 'Invalid UOM ID';
|
|
26
|
-
if (jsonOutput) {
|
|
27
|
-
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_ID', message: errMsg } }));
|
|
28
|
-
} else {
|
|
29
|
-
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
30
|
-
}
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!jsonOutput) {
|
|
35
|
-
console.log(chalk.bold(`\n✓ Enable UOM (${environment})\n`));
|
|
36
|
-
console.log(chalk.gray(` UOM ID: ${uomId}`));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Get UOM details for confirmation
|
|
40
|
-
let uom: Uom | undefined;
|
|
41
|
-
try {
|
|
42
|
-
const uomResponse = await apiClient.getUom(environment, tenant, uomId);
|
|
43
|
-
if (!uomResponse.success || !uomResponse.data || !('uomId' in uomResponse.data)) {
|
|
44
|
-
const errMsg = `UOM not found: ${uomId}`;
|
|
45
|
-
if (jsonOutput) {
|
|
46
|
-
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
47
|
-
} else {
|
|
48
|
-
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
49
|
-
}
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
uom = uomResponse.data as Uom;
|
|
53
|
-
} catch (error) {
|
|
54
|
-
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
55
|
-
if (jsonOutput) {
|
|
56
|
-
console.log(JSON.stringify({ success: false, error: { code: 'FETCH_ERROR', message: `Failed to fetch UOM: ${errMsg}` } }));
|
|
57
|
-
} else {
|
|
58
|
-
console.error(chalk.red(`\n✗ Failed to fetch UOM: ${errMsg}\n`));
|
|
59
|
-
}
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Check if already enabled
|
|
64
|
-
if (uom.statusFlag === 1) {
|
|
65
|
-
const errMsg = `UOM "${uom.uomName}" is already enabled`;
|
|
66
|
-
if (jsonOutput) {
|
|
67
|
-
console.log(JSON.stringify({ success: false, error: { code: 'ALREADY_ENABLED', message: errMsg } }));
|
|
68
|
-
} else {
|
|
69
|
-
console.error(chalk.yellow(`\n⚠ ${errMsg}\n`));
|
|
70
|
-
}
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!jsonOutput) {
|
|
75
|
-
console.log(chalk.gray(` Name: ${uom.uomName}`));
|
|
76
|
-
console.log(chalk.gray(` Code: ${uom.uomCode}`));
|
|
77
|
-
|
|
78
|
-
const { confirm } = await inquirer.prompt([
|
|
79
|
-
{
|
|
80
|
-
type: 'confirm',
|
|
81
|
-
name: 'confirm',
|
|
82
|
-
message: `Enable UOM "${uom.uomName}"?`,
|
|
83
|
-
default: false,
|
|
84
|
-
},
|
|
85
|
-
]);
|
|
86
|
-
|
|
87
|
-
if (!confirm) {
|
|
88
|
-
console.log(chalk.gray('\n Operation cancelled.\n'));
|
|
89
|
-
process.exit(0);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Execute enable
|
|
94
|
-
try {
|
|
95
|
-
const response = await apiClient.enableUom(environment, tenant, uomId);
|
|
96
|
-
|
|
97
|
-
if (response.success) {
|
|
98
|
-
if (jsonOutput) {
|
|
99
|
-
console.log(JSON.stringify({ success: true, uomId, name: uom?.uomName }));
|
|
100
|
-
} else {
|
|
101
|
-
console.log(chalk.green(`\n✓ UOM ${uom?.uomName || uomId} enabled\n`));
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
const errorMsg = response.error?.message || 'Unknown error';
|
|
105
|
-
const errorCode = response.error?.code || 'ENABLE_ERROR';
|
|
106
|
-
if (jsonOutput) {
|
|
107
|
-
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
108
|
-
} else {
|
|
109
|
-
console.error(chalk.red(`\n✗ Failed to enable UOM: ${errorMsg}`));
|
|
110
|
-
if (response.error?.code) {
|
|
111
|
-
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
112
|
-
}
|
|
113
|
-
console.error();
|
|
114
|
-
}
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
} catch (error) {
|
|
118
|
-
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
119
|
-
if (jsonOutput) {
|
|
120
|
-
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
121
|
-
} else {
|
|
122
|
-
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
123
|
-
}
|
|
124
|
-
process.exit(1);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return enableCommand;
|
|
129
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
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 { Uom } from '../../../types/uom.js';
|
|
7
|
-
|
|
8
|
-
export function createUomGetCommand(): Command {
|
|
9
|
-
const getCommand = new Command('get');
|
|
10
|
-
getCommand.description('Get UOM details by ID');
|
|
11
|
-
getCommand.arguments('<uomId>');
|
|
12
|
-
getCommand.option('--json', 'Output as JSON');
|
|
13
|
-
|
|
14
|
-
getCommand.action(async (uomId: 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 (!uomId) {
|
|
20
|
-
console.error(chalk.red('\n✗ UOM ID is required\n'));
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!uomId || uomId.trim() === '') {
|
|
25
|
-
console.error(chalk.red('\n✗ Invalid UOM ID.\n'));
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
const response = await apiClient.getUom(environment, tenant, uomId);
|
|
31
|
-
|
|
32
|
-
if (!response.success) {
|
|
33
|
-
const errorCode = response.error?.code || 'UNKNOWN_ERROR';
|
|
34
|
-
const errorMessage = response.error?.message || 'Unknown error';
|
|
35
|
-
|
|
36
|
-
// Handle "UOM not found" case
|
|
37
|
-
if (errorCode === '01001150001' || errorMessage.includes('不存在')) {
|
|
38
|
-
console.error(chalk.red(`\n✗ UOM not found: ${uomId}\n`));
|
|
39
|
-
} else {
|
|
40
|
-
console.error(chalk.red(`\n✗ Error: ${errorMessage} (${errorCode})\n`));
|
|
41
|
-
}
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const uom = response.data as Uom | null;
|
|
46
|
-
|
|
47
|
-
// Workaround: Commander.js doesn't propagate --json to nested subcommands properly
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
-
(options as any).json = process.argv.includes('--json');
|
|
50
|
-
const outputJson = (options as Record<string, unknown>).json === true;
|
|
51
|
-
|
|
52
|
-
if (!uom) {
|
|
53
|
-
console.error(chalk.red('\n✗ UOM not found\n'));
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (outputJson) {
|
|
58
|
-
console.log(JSON.stringify({
|
|
59
|
-
success: true,
|
|
60
|
-
data: uom,
|
|
61
|
-
}, null, 2));
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Table output
|
|
66
|
-
console.log(chalk.bold('\n📏 UOM Details\n'));
|
|
67
|
-
console.log(` ${chalk.gray('ID:')} ${uom.uomId}`);
|
|
68
|
-
console.log(` ${chalk.gray('Code:')} ${uom.uomCode}`);
|
|
69
|
-
console.log(` ${chalk.gray('Name:')} ${uom.uomName}`);
|
|
70
|
-
console.log(` ${chalk.gray('Fraction Places:')} ${uom.uomFractionPlaces}`);
|
|
71
|
-
console.log(` ${chalk.gray('Status:')} ${uom.statusFlag === 1 ? 'Enable' : 'Disable'}`);
|
|
72
|
-
if (uom.remark) {
|
|
73
|
-
console.log(` ${chalk.gray('Remark:')} ${uom.remark}`);
|
|
74
|
-
}
|
|
75
|
-
console.log();
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.error(chalk.red(`\n✗ Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
return getCommand;
|
|
83
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { createUomListCommand } from './list.js';
|
|
3
|
-
import { createUomGetCommand } from './get.js';
|
|
4
|
-
import { createUomCreateCommand } from './create.js';
|
|
5
|
-
import { createUomUpdateCommand } from './update.js';
|
|
6
|
-
import { createUomDeleteCommand } from './delete.js';
|
|
7
|
-
import { createUomEnableCommand } from './enable.js';
|
|
8
|
-
import { createUomDisableCommand } from './disable.js';
|
|
9
|
-
|
|
10
|
-
export function createUomsCommand(): Command {
|
|
11
|
-
const uomsCommand = new Command('uoms');
|
|
12
|
-
uomsCommand.description('Manage units of measure');
|
|
13
|
-
|
|
14
|
-
uomsCommand.addCommand(createUomListCommand());
|
|
15
|
-
uomsCommand.addCommand(createUomGetCommand());
|
|
16
|
-
uomsCommand.addCommand(createUomCreateCommand());
|
|
17
|
-
uomsCommand.addCommand(createUomUpdateCommand());
|
|
18
|
-
uomsCommand.addCommand(createUomDeleteCommand());
|
|
19
|
-
uomsCommand.addCommand(createUomEnableCommand());
|
|
20
|
-
uomsCommand.addCommand(createUomDisableCommand());
|
|
21
|
-
|
|
22
|
-
return uomsCommand;
|
|
23
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
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 { UomListResponse, UomStatusFlag } from '../../../types/uom.js';
|
|
7
|
-
import { Environment } from '../../../types/index.js';
|
|
8
|
-
|
|
9
|
-
export function createUomListCommand(): Command {
|
|
10
|
-
const listCommand = new Command('list');
|
|
11
|
-
listCommand.description('List UOMs with pagination');
|
|
12
|
-
|
|
13
|
-
listCommand
|
|
14
|
-
.option('-p, --page <number>', 'Page number', '1')
|
|
15
|
-
.option('-s, --size <number>', 'Page size', '20')
|
|
16
|
-
.option('--status <string>', 'Status filter (enable/disable)')
|
|
17
|
-
.option('--json', 'Output as JSON')
|
|
18
|
-
.action(async (options) => {
|
|
19
|
-
// Commander.js boolean flag parsing workaround
|
|
20
|
-
const outputJson = options.json === true || process.argv.includes('--json');
|
|
21
|
-
|
|
22
|
-
const context = configManager.getCurrentContext();
|
|
23
|
-
const environment = (options.env as Environment) || context.environment;
|
|
24
|
-
const tenant = options.tenant || context.tenant;
|
|
25
|
-
|
|
26
|
-
const page = parseInt(options.page as string, 10) - 1;
|
|
27
|
-
const size = parseInt(options.size as string, 10);
|
|
28
|
-
|
|
29
|
-
const params: {
|
|
30
|
-
pageNo: number;
|
|
31
|
-
pageSize: number;
|
|
32
|
-
status?: UomStatusFlag;
|
|
33
|
-
} = { pageNo: page, pageSize: size };
|
|
34
|
-
|
|
35
|
-
if (options.status !== undefined) {
|
|
36
|
-
const statusVal = (options.status as string).toLowerCase();
|
|
37
|
-
if (statusVal === 'enable' || statusVal === '1') {
|
|
38
|
-
params.status = 1;
|
|
39
|
-
} else if (statusVal === 'disable' || statusVal === '2') {
|
|
40
|
-
params.status = 2;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const response = await apiClient.listUoms(environment, tenant, params);
|
|
45
|
-
|
|
46
|
-
if (!response.success) {
|
|
47
|
-
console.error(chalk.red(`\n✗ Failed to list UOMs: ${response.error?.message || 'Unknown error'}`));
|
|
48
|
-
if (response.error?.code) {
|
|
49
|
-
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
50
|
-
}
|
|
51
|
-
console.error();
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const data = response.data as UomListResponse | null;
|
|
56
|
-
|
|
57
|
-
if (!data) {
|
|
58
|
-
if (outputJson) {
|
|
59
|
-
console.log(JSON.stringify({ success: true, data: { items: [], pagination: { pageNo: 0, pageSize: 20, totalRows: 0 } } }, null, 2));
|
|
60
|
-
} else {
|
|
61
|
-
console.log(chalk.bold('\n📏 UOM List\n'));
|
|
62
|
-
console.log(chalk.gray(' No UOMs found\n'));
|
|
63
|
-
}
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (outputJson) {
|
|
68
|
-
console.log(
|
|
69
|
-
JSON.stringify(
|
|
70
|
-
{
|
|
71
|
-
success: true,
|
|
72
|
-
data: {
|
|
73
|
-
items: data.rows || [],
|
|
74
|
-
pagination: {
|
|
75
|
-
pageNo: data.pageNo,
|
|
76
|
-
pageSize: data.pageSize,
|
|
77
|
-
totalRows: data.totalRows,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
null,
|
|
82
|
-
2
|
|
83
|
-
)
|
|
84
|
-
);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const records = data.rows || [];
|
|
89
|
-
|
|
90
|
-
if (records.length === 0) {
|
|
91
|
-
console.log(chalk.bold('\n📏 UOM List\n'));
|
|
92
|
-
console.log(chalk.gray(' No UOMs found\n'));
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
console.log(chalk.bold('\n📏 UOM List\n'));
|
|
97
|
-
|
|
98
|
-
const table = new Table({
|
|
99
|
-
head: [chalk.bold('ID'), chalk.bold('Code'), chalk.bold('Name'), chalk.bold('Fraction Places'), chalk.bold('Status')],
|
|
100
|
-
colWidths: [14, 14, 30, 18, 10],
|
|
101
|
-
style: {
|
|
102
|
-
head: [],
|
|
103
|
-
border: [],
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
for (const uom of records) {
|
|
108
|
-
const statusText = uom.statusFlag === 1 ? chalk.green('Enable') : chalk.red('Disable');
|
|
109
|
-
table.push([
|
|
110
|
-
uom.uomId,
|
|
111
|
-
uom.uomCode || '-',
|
|
112
|
-
uom.uomName || '-',
|
|
113
|
-
uom.uomFractionPlaces?.toString() || '-',
|
|
114
|
-
statusText,
|
|
115
|
-
]);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
console.log(table.toString());
|
|
119
|
-
console.log();
|
|
120
|
-
console.log(
|
|
121
|
-
chalk.gray(
|
|
122
|
-
` Total: ${data.totalRows} | Page: ${data.pageNo + 1} / ${Math.ceil(data.totalRows / data.pageSize) || 1} | Size: ${data.pageSize}`
|
|
123
|
-
)
|
|
124
|
-
);
|
|
125
|
-
console.log();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return listCommand;
|
|
129
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
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 { Uom, UpdateUomRequest } from '../../../types/uom.js';
|
|
6
|
-
import { Environment } from '../../../types/index.js';
|
|
7
|
-
|
|
8
|
-
export function createUomUpdateCommand(): Command {
|
|
9
|
-
const updateCommand = new Command('update');
|
|
10
|
-
updateCommand.description('Update UOM information').argument('<uomId>', 'UOM ID');
|
|
11
|
-
|
|
12
|
-
updateCommand
|
|
13
|
-
.option('-n, --name <name>', 'UOM name')
|
|
14
|
-
.option('--fraction-places <number>', 'Fraction places')
|
|
15
|
-
.option('--remark <text>', 'Remark')
|
|
16
|
-
.option('--dry-run', 'Preview changes without making API call')
|
|
17
|
-
.option('--json', 'Output result as JSON')
|
|
18
|
-
.action(async (uomId: string, options: Record<string, unknown>) => {
|
|
19
|
-
const context = configManager.getCurrentContext();
|
|
20
|
-
const environment = context.environment as Environment;
|
|
21
|
-
const tenant = context.tenant;
|
|
22
|
-
|
|
23
|
-
const fields: Partial<UpdateUomRequest> = {};
|
|
24
|
-
if (options.name) fields.uomName = options.name as string;
|
|
25
|
-
if (options.fractionPlaces) fields.uomFractionPlaces = parseInt(options.fractionPlaces as string, 10);
|
|
26
|
-
if (options.remark) fields.remark = options.remark as string;
|
|
27
|
-
|
|
28
|
-
const providedFields = Object.keys(fields).filter(
|
|
29
|
-
(k) => fields[k as keyof UpdateUomRequest] !== undefined
|
|
30
|
-
);
|
|
31
|
-
if (providedFields.length === 0) {
|
|
32
|
-
console.error(
|
|
33
|
-
chalk.red('\n✗ No fields to update. Provide at least one of: --name, --fraction-places, --remark\n')
|
|
34
|
-
);
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (options.dryRun) {
|
|
39
|
-
console.log(chalk.bold(`\n📏 Update UOM — Dry Run (${environment})\n`));
|
|
40
|
-
console.log(chalk.gray(` UOM ID: ${uomId}`));
|
|
41
|
-
console.log(chalk.gray('\n Changes to be applied:'));
|
|
42
|
-
for (const field of providedFields) {
|
|
43
|
-
const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
|
|
44
|
-
console.log(chalk.cyan(` ${label}: "${fields[field as keyof UpdateUomRequest]}"`));
|
|
45
|
-
}
|
|
46
|
-
console.log();
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let currentUom: Uom | undefined;
|
|
51
|
-
try {
|
|
52
|
-
const uomResponse = await apiClient.getUom(environment, tenant, uomId);
|
|
53
|
-
if (!uomResponse.success || !uomResponse.data) {
|
|
54
|
-
console.error(chalk.red(`\n✗ UOM not found: ${uomId}`));
|
|
55
|
-
if (uomResponse.error?.message) {
|
|
56
|
-
console.error(chalk.gray(` ${uomResponse.error.message}`));
|
|
57
|
-
}
|
|
58
|
-
if (uomResponse.error?.code) {
|
|
59
|
-
console.error(chalk.gray(` Error code: ${uomResponse.error.code}`));
|
|
60
|
-
}
|
|
61
|
-
console.error();
|
|
62
|
-
process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
currentUom = uomResponse.data as Uom;
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.error(chalk.red(`\n✗ Failed to fetch UOM: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
-
(options as any).json = process.argv.includes('--json');
|
|
72
|
-
const outputJson = (options as Record<string, unknown>).json === true;
|
|
73
|
-
|
|
74
|
-
console.log(chalk.bold(`\n📏 Update UOM (${environment})\n`));
|
|
75
|
-
console.log(chalk.gray(` UOM ID: ${uomId}`));
|
|
76
|
-
console.log(chalk.gray(` Current Code: ${currentUom.uomCode}`));
|
|
77
|
-
console.log(chalk.gray(` Current Name: ${currentUom.uomName}`));
|
|
78
|
-
console.log(chalk.gray('\n Changes:'));
|
|
79
|
-
for (const field of providedFields) {
|
|
80
|
-
const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
|
|
81
|
-
const currentVal = (currentUom as unknown as Record<string, unknown>)[field] ?? '(not set)';
|
|
82
|
-
const newVal = fields[field as keyof UpdateUomRequest];
|
|
83
|
-
console.log(chalk.cyan(` ${label}: "${currentVal}" → "${newVal}"`));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const updateData = { uomId, ...fields } as UpdateUomRequest;
|
|
87
|
-
try {
|
|
88
|
-
const response = await apiClient.updateUom(environment, tenant, updateData);
|
|
89
|
-
|
|
90
|
-
if (response.success) {
|
|
91
|
-
if (outputJson) {
|
|
92
|
-
console.log(JSON.stringify({ success: true, data: response.data }, null, 2));
|
|
93
|
-
} else {
|
|
94
|
-
console.log(chalk.green(`\n✓ UOM updated successfully\n`));
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
if (outputJson) {
|
|
98
|
-
console.log(JSON.stringify({ success: false, error: response.error }, null, 2));
|
|
99
|
-
} else {
|
|
100
|
-
console.error(chalk.red(`\n✗ Update failed: ${response.error?.message || 'Unknown error'}`));
|
|
101
|
-
if (response.error?.code) {
|
|
102
|
-
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
103
|
-
}
|
|
104
|
-
console.error();
|
|
105
|
-
}
|
|
106
|
-
process.exit(1);
|
|
107
|
-
}
|
|
108
|
-
} catch (error) {
|
|
109
|
-
if (outputJson) {
|
|
110
|
-
console.log(
|
|
111
|
-
JSON.stringify({
|
|
112
|
-
success: false,
|
|
113
|
-
error: { message: error instanceof Error ? error.message : 'Unknown error' },
|
|
114
|
-
})
|
|
115
|
-
);
|
|
116
|
-
} else {
|
|
117
|
-
console.error(chalk.red(`\n✗ Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
118
|
-
}
|
|
119
|
-
process.exit(1);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
return updateCommand;
|
|
124
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { configManager } from '../../../core/config/manager.js';
|
|
3
|
-
import { apiClient } from '../../../core/api/client.js';
|
|
4
|
-
import { Environment } from '../../../types/index.js';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
|
|
7
|
-
export function createUserCreateCommand(): Command {
|
|
8
|
-
const createCommand = new Command('create');
|
|
9
|
-
createCommand.description('Create a new user');
|
|
10
|
-
|
|
11
|
-
createCommand
|
|
12
|
-
.option('-n, --name <name>', 'User real name (required)')
|
|
13
|
-
.option('-a, --account <account>', 'User account (required)')
|
|
14
|
-
.option('-e, --email <email>', 'User email')
|
|
15
|
-
.option('-r, --role-ids <roleIds>', 'Role IDs (comma-separated, required)')
|
|
16
|
-
.option('--employee-code <employeeCode>', 'Employee code (optional, used to find employee)')
|
|
17
|
-
.option('--employee-name <employeeName>', 'Employee name (optional, used to find employee)')
|
|
18
|
-
.option('--org-id <orgId>', 'Organization ID (optional, auto-assigned if not provided)')
|
|
19
|
-
.option('--dry-run', 'Preview without executing')
|
|
20
|
-
.option('--json', 'Output as JSON')
|
|
21
|
-
.action(async (options) => {
|
|
22
|
-
// Commander.js boolean flag parsing workaround
|
|
23
|
-
options.dryRun = process.argv.includes('--dry-run');
|
|
24
|
-
options.json = process.argv.includes('--json');
|
|
25
|
-
|
|
26
|
-
const context = configManager.getCurrentContext();
|
|
27
|
-
const environment = (options.env as Environment) || context.environment;
|
|
28
|
-
const tenant = options.tenant || context.tenant;
|
|
29
|
-
|
|
30
|
-
if (!options.name || !options.account || !options.roleIds) {
|
|
31
|
-
console.error(chalk.red('\n✗ Missing required options: --name, --account, --role-ids\n'));
|
|
32
|
-
createCommand.help();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const roleIdList = options.roleIds.split(',').map((id: string) => id.trim());
|
|
36
|
-
|
|
37
|
-
const userData: any = {
|
|
38
|
-
realName: options.name,
|
|
39
|
-
account: options.account,
|
|
40
|
-
email: options.email,
|
|
41
|
-
roleIdList,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
if (options.employeeCode || options.employeeName) {
|
|
45
|
-
const searchText = options.employeeCode || options.employeeName;
|
|
46
|
-
const searchResponse = await apiClient.searchEmployees(environment, tenant, searchText);
|
|
47
|
-
if (!searchResponse.success) {
|
|
48
|
-
console.error(chalk.red(`\n✗ 职员搜索失败: ${searchResponse.error?.message}\n`));
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
let employees = searchResponse.data || [];
|
|
53
|
-
|
|
54
|
-
if (options.employeeCode && options.employeeName) {
|
|
55
|
-
employees = employees.filter((emp: any) =>
|
|
56
|
-
emp.code === options.employeeCode &&
|
|
57
|
-
emp.name && emp.name.includes(options.employeeName)
|
|
58
|
-
);
|
|
59
|
-
} else if (options.employeeCode) {
|
|
60
|
-
employees = employees.filter((emp: any) => emp.code === options.employeeCode);
|
|
61
|
-
} else if (options.employeeName) {
|
|
62
|
-
employees = employees.filter((emp: any) =>
|
|
63
|
-
emp.name && emp.name.includes(options.employeeName)
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (employees.length === 0) {
|
|
68
|
-
console.error(chalk.red('\n✗ 未找到匹配的职员\n'));
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (employees.length > 1) {
|
|
73
|
-
console.error(chalk.red(`\n✗ 找到多个职员,请使用更精确的条件\n`));
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const employee = employees[0];
|
|
78
|
-
userData.employeeCode = employee.code;
|
|
79
|
-
userData.employeeNumber = employee.no;
|
|
80
|
-
userData.employeeId = employee.id;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 检查账号是否已存在
|
|
84
|
-
const existCheckResponse = await apiClient.existCheck(environment, tenant, options.account);
|
|
85
|
-
if (!existCheckResponse.success) {
|
|
86
|
-
console.error(chalk.red(`\n✗ 账号校验失败: ${existCheckResponse.error?.message}\n`));
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// 如果账号已存在,根据模式处理
|
|
91
|
-
if (existCheckResponse.data === false) {
|
|
92
|
-
if (options.dryRun) {
|
|
93
|
-
console.log(chalk.yellow(`\n⚠️ 警告: 账号 "${options.account}" 已存在 (dry-run模式继续预览)\n`));
|
|
94
|
-
} else {
|
|
95
|
-
console.error(chalk.red(`\n✗ 账号 "${options.account}" 已存在,请使用其他账号\n`));
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!options.dryRun) {
|
|
101
|
-
try {
|
|
102
|
-
const userIndexResponse = await apiClient.getUserIndexInfo(environment, tenant);
|
|
103
|
-
if (userIndexResponse.success && userIndexResponse.data?.userOrgInfoList?.length > 0) {
|
|
104
|
-
const firstOrg = userIndexResponse.data.userOrgInfoList[0];
|
|
105
|
-
await apiClient.updateUserOrgOrApp(environment, tenant, { newOrgId: String(firstOrg.orgId) });
|
|
106
|
-
}
|
|
107
|
-
} catch (err) {
|
|
108
|
-
// ignore errors during org switch
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (options.dryRun) {
|
|
113
|
-
console.log(chalk.bold('\n🔍 Dry-Run Mode: No changes will be made\n'));
|
|
114
|
-
console.log(chalk.gray('User Data:'));
|
|
115
|
-
console.log(JSON.stringify(userData, null, 2));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const response = await apiClient.createUser(environment, tenant, userData);
|
|
120
|
-
|
|
121
|
-
if (!response.success) {
|
|
122
|
-
console.error(chalk.red(`\n✗ Failed: ${response.error?.message}\n`));
|
|
123
|
-
process.exit(1);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
console.log(chalk.green('\n✓ User created successfully\n'));
|
|
127
|
-
if (options.json) {
|
|
128
|
-
console.log(JSON.stringify({ success: true, data: response.data }, null, 2));
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return createCommand;
|
|
133
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
|
|
8
|
-
export function createUserDeleteCommand(): Command {
|
|
9
|
-
const deleteCommand = new Command('delete');
|
|
10
|
-
deleteCommand.description('Delete a user');
|
|
11
|
-
|
|
12
|
-
deleteCommand
|
|
13
|
-
.argument('<userId>', 'User ID')
|
|
14
|
-
.option('--force', 'Skip confirmation')
|
|
15
|
-
.option('--dry-run', 'Preview without executing')
|
|
16
|
-
.option('--json', 'Output as JSON')
|
|
17
|
-
.action(async (userId, options) => {
|
|
18
|
-
const context = configManager.getCurrentContext();
|
|
19
|
-
const environment = (options.env as Environment) || context.environment;
|
|
20
|
-
const tenant = options.tenant || context.tenant;
|
|
21
|
-
|
|
22
|
-
if (options.dryRun) {
|
|
23
|
-
console.log(chalk.bold('\n🔍 Dry-Run Mode\n'));
|
|
24
|
-
console.log(chalk.gray(`Would delete user: ${userId}`));
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (!options.force) {
|
|
29
|
-
const { confirm } = await inquirer.prompt([
|
|
30
|
-
{ type: 'confirm', name: 'confirm', message: `Delete user ${userId}?`, default: false },
|
|
31
|
-
]);
|
|
32
|
-
if (!confirm) {
|
|
33
|
-
console.log(chalk.yellow('\n↩ Cancelled\n'));
|
|
34
|
-
process.exit(0);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const response = await apiClient.deleteUser(environment, tenant, userId);
|
|
39
|
-
|
|
40
|
-
if (!response.success) {
|
|
41
|
-
console.error(chalk.red(`\n✗ Failed: ${response.error?.message}\n`));
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
console.log(chalk.green('\n✓ User deleted successfully\n'));
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return deleteCommand;
|
|
49
|
-
}
|