@newpeak/barista-cli 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/liberica/auth/index.d.ts.map +1 -1
- package/dist/commands/liberica/auth/index.js +5 -0
- package/dist/commands/liberica/auth/index.js.map +1 -1
- package/dist/commands/liberica/currency/create.d.ts +3 -0
- package/dist/commands/liberica/currency/create.d.ts.map +1 -0
- package/dist/commands/liberica/currency/create.js +168 -0
- package/dist/commands/liberica/currency/create.js.map +1 -0
- package/dist/commands/liberica/currency/delete.d.ts +3 -0
- package/dist/commands/liberica/currency/delete.d.ts.map +1 -0
- package/dist/commands/liberica/currency/delete.js +122 -0
- package/dist/commands/liberica/currency/delete.js.map +1 -0
- package/dist/commands/liberica/currency/disable.d.ts +3 -0
- package/dist/commands/liberica/currency/disable.d.ts.map +1 -0
- package/dist/commands/liberica/currency/disable.js +145 -0
- package/dist/commands/liberica/currency/disable.js.map +1 -0
- package/dist/commands/liberica/currency/enable.d.ts +3 -0
- package/dist/commands/liberica/currency/enable.d.ts.map +1 -0
- package/dist/commands/liberica/currency/enable.js +125 -0
- package/dist/commands/liberica/currency/enable.js.map +1 -0
- package/dist/commands/liberica/currency/get.d.ts +3 -0
- package/dist/commands/liberica/currency/get.d.ts.map +1 -0
- package/dist/commands/liberica/currency/get.js +80 -0
- package/dist/commands/liberica/currency/get.js.map +1 -0
- package/dist/commands/liberica/currency/index.d.ts +3 -0
- package/dist/commands/liberica/currency/index.d.ts.map +1 -0
- package/dist/commands/liberica/currency/index.js +21 -0
- package/dist/commands/liberica/currency/index.js.map +1 -0
- package/dist/commands/liberica/currency/list.d.ts +3 -0
- package/dist/commands/liberica/currency/list.d.ts.map +1 -0
- package/dist/commands/liberica/currency/list.js +106 -0
- package/dist/commands/liberica/currency/list.js.map +1 -0
- package/dist/commands/liberica/currency/update.d.ts +3 -0
- package/dist/commands/liberica/currency/update.d.ts.map +1 -0
- package/dist/commands/liberica/currency/update.js +123 -0
- package/dist/commands/liberica/currency/update.js.map +1 -0
- package/dist/commands/liberica/index.d.ts.map +1 -1
- package/dist/commands/liberica/index.js +11 -0
- package/dist/commands/liberica/index.js.map +1 -1
- package/dist/commands/liberica/materials/create.d.ts +3 -0
- package/dist/commands/liberica/materials/create.d.ts.map +1 -0
- package/dist/commands/liberica/materials/create.js +154 -0
- package/dist/commands/liberica/materials/create.js.map +1 -0
- package/dist/commands/liberica/materials/delete.d.ts +3 -0
- package/dist/commands/liberica/materials/delete.d.ts.map +1 -0
- package/dist/commands/liberica/materials/delete.js +104 -0
- package/dist/commands/liberica/materials/delete.js.map +1 -0
- package/dist/commands/liberica/materials/disable.d.ts +3 -0
- package/dist/commands/liberica/materials/disable.d.ts.map +1 -0
- package/dist/commands/liberica/materials/disable.js +146 -0
- package/dist/commands/liberica/materials/disable.js.map +1 -0
- package/dist/commands/liberica/materials/enable.d.ts +3 -0
- package/dist/commands/liberica/materials/enable.d.ts.map +1 -0
- package/dist/commands/liberica/materials/enable.js +126 -0
- package/dist/commands/liberica/materials/enable.js.map +1 -0
- package/dist/commands/liberica/materials/get.d.ts +3 -0
- package/dist/commands/liberica/materials/get.d.ts.map +1 -0
- package/dist/commands/liberica/materials/get.js +71 -0
- package/dist/commands/liberica/materials/get.js.map +1 -0
- package/dist/commands/liberica/materials/index.d.ts +3 -0
- package/dist/commands/liberica/materials/index.d.ts.map +1 -0
- package/dist/commands/liberica/materials/index.js +21 -0
- package/dist/commands/liberica/materials/index.js.map +1 -0
- package/dist/commands/liberica/materials/list.d.ts +3 -0
- package/dist/commands/liberica/materials/list.d.ts.map +1 -0
- package/dist/commands/liberica/materials/list.js +107 -0
- package/dist/commands/liberica/materials/list.js.map +1 -0
- package/dist/commands/liberica/materials/update.d.ts +3 -0
- package/dist/commands/liberica/materials/update.d.ts.map +1 -0
- package/dist/commands/liberica/materials/update.js +118 -0
- package/dist/commands/liberica/materials/update.js.map +1 -0
- package/dist/commands/liberica/suppliers/create.d.ts +3 -0
- package/dist/commands/liberica/suppliers/create.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/create.js +140 -0
- package/dist/commands/liberica/suppliers/create.js.map +1 -0
- package/dist/commands/liberica/suppliers/delete.d.ts +3 -0
- package/dist/commands/liberica/suppliers/delete.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/delete.js +102 -0
- package/dist/commands/liberica/suppliers/delete.js.map +1 -0
- package/dist/commands/liberica/suppliers/disable.d.ts +3 -0
- package/dist/commands/liberica/suppliers/disable.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/disable.js +144 -0
- package/dist/commands/liberica/suppliers/disable.js.map +1 -0
- package/dist/commands/liberica/suppliers/enable.d.ts +3 -0
- package/dist/commands/liberica/suppliers/enable.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/enable.js +124 -0
- package/dist/commands/liberica/suppliers/enable.js.map +1 -0
- package/dist/commands/liberica/suppliers/get.d.ts +3 -0
- package/dist/commands/liberica/suppliers/get.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/get.js +75 -0
- package/dist/commands/liberica/suppliers/get.js.map +1 -0
- package/dist/commands/liberica/suppliers/index.d.ts +3 -0
- package/dist/commands/liberica/suppliers/index.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/index.js +21 -0
- package/dist/commands/liberica/suppliers/index.js.map +1 -0
- package/dist/commands/liberica/suppliers/list.d.ts +3 -0
- package/dist/commands/liberica/suppliers/list.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/list.js +100 -0
- package/dist/commands/liberica/suppliers/list.js.map +1 -0
- package/dist/commands/liberica/suppliers/update.d.ts +3 -0
- package/dist/commands/liberica/suppliers/update.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/update.js +122 -0
- package/dist/commands/liberica/suppliers/update.js.map +1 -0
- package/dist/commands/liberica/uoms/create.d.ts +3 -0
- package/dist/commands/liberica/uoms/create.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/create.js +120 -0
- package/dist/commands/liberica/uoms/create.js.map +1 -0
- package/dist/commands/liberica/uoms/delete.d.ts +3 -0
- package/dist/commands/liberica/uoms/delete.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/delete.js +104 -0
- package/dist/commands/liberica/uoms/delete.js.map +1 -0
- package/dist/commands/liberica/uoms/disable.d.ts +3 -0
- package/dist/commands/liberica/uoms/disable.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/disable.js +146 -0
- package/dist/commands/liberica/uoms/disable.js.map +1 -0
- package/dist/commands/liberica/uoms/enable.d.ts +3 -0
- package/dist/commands/liberica/uoms/enable.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/enable.js +126 -0
- package/dist/commands/liberica/uoms/enable.js.map +1 -0
- package/dist/commands/liberica/uoms/get.d.ts +3 -0
- package/dist/commands/liberica/uoms/get.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/get.js +71 -0
- package/dist/commands/liberica/uoms/get.js.map +1 -0
- package/dist/commands/liberica/uoms/index.d.ts +3 -0
- package/dist/commands/liberica/uoms/index.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/index.js +21 -0
- package/dist/commands/liberica/uoms/index.js.map +1 -0
- package/dist/commands/liberica/uoms/list.d.ts +3 -0
- package/dist/commands/liberica/uoms/list.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/list.js +98 -0
- package/dist/commands/liberica/uoms/list.js.map +1 -0
- package/dist/commands/liberica/uoms/update.d.ts +3 -0
- package/dist/commands/liberica/uoms/update.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/update.js +115 -0
- package/dist/commands/liberica/uoms/update.js.map +1 -0
- package/dist/core/api/client.d.ts +34 -0
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +650 -0
- package/dist/core/api/client.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/currency.d.ts +74 -0
- package/dist/types/currency.d.ts.map +1 -0
- package/dist/types/currency.js +2 -0
- package/dist/types/currency.js.map +1 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/material.d.ts +49 -0
- package/dist/types/material.d.ts.map +1 -0
- package/dist/types/material.js +2 -0
- package/dist/types/material.js.map +1 -0
- package/dist/types/supplier.d.ts +53 -0
- package/dist/types/supplier.d.ts.map +1 -0
- package/dist/types/supplier.js +2 -0
- package/dist/types/supplier.js.map +1 -0
- package/dist/types/uom.d.ts +47 -0
- package/dist/types/uom.d.ts.map +1 -0
- package/dist/types/uom.js +2 -0
- package/dist/types/uom.js.map +1 -0
- package/docs/COMMAND_DESIGN_SPEC.md +42 -13
- package/docs/commands/liberica/currency/create.md +145 -0
- package/docs/commands/liberica/currency/delete.md +121 -0
- package/docs/commands/liberica/currency/disable.md +119 -0
- package/docs/commands/liberica/currency/enable.md +115 -0
- package/docs/commands/liberica/currency/get.md +118 -0
- package/docs/commands/liberica/currency/list.md +149 -0
- package/docs/commands/liberica/currency/update.md +141 -0
- package/docs/commands/liberica/materials/create.md +293 -0
- package/docs/commands/liberica/materials/delete.md +240 -0
- package/docs/commands/liberica/materials/disable.md +150 -0
- package/docs/commands/liberica/materials/enable.md +146 -0
- package/docs/commands/liberica/materials/get.md +188 -0
- package/docs/commands/liberica/materials/list.md +198 -0
- package/docs/commands/liberica/materials/update.md +250 -0
- package/docs/commands/liberica/uoms/create.md +136 -0
- package/docs/commands/liberica/uoms/delete.md +119 -0
- package/docs/commands/liberica/uoms/disable.md +117 -0
- package/docs/commands/liberica/uoms/enable.md +115 -0
- package/docs/commands/liberica/uoms/get.md +119 -0
- package/docs/commands/liberica/uoms/list.md +155 -0
- package/docs/commands/liberica/uoms/update.md +148 -0
- package/package.json +2 -4
- package/src/commands/liberica/auth/index.ts +6 -0
- package/src/commands/liberica/currency/create.ts +183 -0
- package/src/commands/liberica/currency/delete.ts +124 -0
- package/src/commands/liberica/currency/disable.ts +147 -0
- package/src/commands/liberica/currency/enable.ts +128 -0
- package/src/commands/liberica/currency/get.ts +91 -0
- package/src/commands/liberica/currency/index.ts +23 -0
- package/src/commands/liberica/currency/list.ts +140 -0
- package/src/commands/liberica/currency/update.ts +129 -0
- package/src/commands/liberica/index.ts +11 -0
- package/src/commands/liberica/materials/create.ts +168 -0
- package/src/commands/liberica/materials/delete.ts +105 -0
- package/src/commands/liberica/materials/disable.ts +148 -0
- package/src/commands/liberica/materials/enable.ts +129 -0
- package/src/commands/liberica/materials/get.ts +83 -0
- package/src/commands/liberica/materials/index.ts +23 -0
- package/src/commands/liberica/materials/list.ts +142 -0
- package/src/commands/liberica/materials/update.ts +125 -0
- package/src/commands/liberica/suppliers/create.ts +149 -0
- package/src/commands/liberica/suppliers/delete.ts +102 -0
- package/src/commands/liberica/suppliers/disable.ts +145 -0
- package/src/commands/liberica/suppliers/enable.ts +126 -0
- package/src/commands/liberica/suppliers/get.ts +86 -0
- package/src/commands/liberica/suppliers/index.ts +23 -0
- package/src/commands/liberica/suppliers/list.ts +134 -0
- package/src/commands/liberica/suppliers/update.ts +128 -0
- package/src/commands/liberica/uoms/create.ts +134 -0
- package/src/commands/liberica/uoms/delete.ts +105 -0
- package/src/commands/liberica/uoms/disable.ts +148 -0
- package/src/commands/liberica/uoms/enable.ts +129 -0
- package/src/commands/liberica/uoms/get.ts +83 -0
- package/src/commands/liberica/uoms/index.ts +23 -0
- package/src/commands/liberica/uoms/list.ts +129 -0
- package/src/commands/liberica/uoms/update.ts +124 -0
- package/src/core/api/client.ts +878 -57
- package/src/index.ts +1 -1
- package/src/types/currency.ts +90 -0
- package/src/types/index.ts +5 -2
- package/src/types/material.ts +61 -0
- package/src/types/supplier.ts +66 -0
- package/src/types/uom.ts +60 -0
- package/bin/barista.js +0 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { createMaterialsCreateCommand } from './create.js';
|
|
3
|
+
import { createMaterialListCommand } from './list.js';
|
|
4
|
+
import { createMaterialsGetCommand } from './get.js';
|
|
5
|
+
import { createMaterialEnableCommand } from './enable.js';
|
|
6
|
+
import { createMaterialDisableCommand } from './disable.js';
|
|
7
|
+
import { createMaterialUpdateCommand } from './update.js';
|
|
8
|
+
import { createMaterialDeleteCommand } from './delete.js';
|
|
9
|
+
|
|
10
|
+
export function createMaterialsCommand(): Command {
|
|
11
|
+
const materialsCommand = new Command('materials');
|
|
12
|
+
materialsCommand.description('Manage materials');
|
|
13
|
+
|
|
14
|
+
materialsCommand.addCommand(createMaterialsCreateCommand());
|
|
15
|
+
materialsCommand.addCommand(createMaterialListCommand());
|
|
16
|
+
materialsCommand.addCommand(createMaterialsGetCommand());
|
|
17
|
+
materialsCommand.addCommand(createMaterialEnableCommand());
|
|
18
|
+
materialsCommand.addCommand(createMaterialDisableCommand());
|
|
19
|
+
materialsCommand.addCommand(createMaterialUpdateCommand());
|
|
20
|
+
materialsCommand.addCommand(createMaterialDeleteCommand());
|
|
21
|
+
|
|
22
|
+
return materialsCommand;
|
|
23
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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 { MaterialListResponse, MaterialStatusFlag } from '../../../types/material.js';
|
|
7
|
+
import { Environment } from '../../../types/index.js';
|
|
8
|
+
|
|
9
|
+
export function createMaterialListCommand(): Command {
|
|
10
|
+
const listCommand = new Command('list');
|
|
11
|
+
listCommand.description('List materials 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('-c, --class <string>', 'Material class filter')
|
|
18
|
+
.option('-k, --keyword <string>', 'Keyword search')
|
|
19
|
+
.option('--json', 'Output as JSON')
|
|
20
|
+
.action(async (options) => {
|
|
21
|
+
// Commander.js boolean flag parsing workaround
|
|
22
|
+
const outputJson = options.json === true || process.argv.includes('--json');
|
|
23
|
+
|
|
24
|
+
const context = configManager.getCurrentContext();
|
|
25
|
+
const environment = (options.env as Environment) || context.environment;
|
|
26
|
+
const tenant = options.tenant || context.tenant;
|
|
27
|
+
|
|
28
|
+
const page = parseInt(options.page as string, 10) - 1;
|
|
29
|
+
const size = parseInt(options.size as string, 10);
|
|
30
|
+
|
|
31
|
+
const params: {
|
|
32
|
+
pageNo: number;
|
|
33
|
+
pageSize: number;
|
|
34
|
+
statusFlag?: MaterialStatusFlag;
|
|
35
|
+
materialClass?: string;
|
|
36
|
+
keyword?: string;
|
|
37
|
+
} = { pageNo: page, pageSize: size };
|
|
38
|
+
|
|
39
|
+
if (options.status !== undefined) {
|
|
40
|
+
const statusVal = (options.status as string).toLowerCase();
|
|
41
|
+
if (statusVal === 'enable' || statusVal === '1') {
|
|
42
|
+
params.statusFlag = 1;
|
|
43
|
+
} else if (statusVal === 'disable' || statusVal === '2') {
|
|
44
|
+
params.statusFlag = 2;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (options.class !== undefined) {
|
|
49
|
+
params.materialClass = options.class as string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (options.keyword !== undefined) {
|
|
53
|
+
params.keyword = options.keyword as string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const response = await apiClient.listMaterials(environment, tenant, params);
|
|
57
|
+
|
|
58
|
+
if (!response.success) {
|
|
59
|
+
console.error(chalk.red(`\n✗ Failed to list materials: ${response.error?.message || 'Unknown error'}`));
|
|
60
|
+
if (response.error?.code) {
|
|
61
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
62
|
+
}
|
|
63
|
+
console.error();
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const data = response.data as MaterialListResponse | null;
|
|
68
|
+
|
|
69
|
+
if (!data) {
|
|
70
|
+
if (outputJson) {
|
|
71
|
+
console.log(JSON.stringify({ success: true, data: { items: [], pagination: { pageNo: 0, pageSize: 20, totalRows: 0 } } }, null, 2));
|
|
72
|
+
} else {
|
|
73
|
+
console.log(chalk.bold('\n📦 Material List\n'));
|
|
74
|
+
console.log(chalk.gray(' No materials found\n'));
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (outputJson) {
|
|
80
|
+
console.log(
|
|
81
|
+
JSON.stringify(
|
|
82
|
+
{
|
|
83
|
+
success: true,
|
|
84
|
+
data: {
|
|
85
|
+
items: data.rows || [],
|
|
86
|
+
pagination: {
|
|
87
|
+
pageNo: data.pageNo,
|
|
88
|
+
pageSize: data.pageSize,
|
|
89
|
+
totalRows: data.totalRows,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
null,
|
|
94
|
+
2
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const records = data.rows || [];
|
|
101
|
+
|
|
102
|
+
if (records.length === 0) {
|
|
103
|
+
console.log(chalk.bold('\n📦 Material List\n'));
|
|
104
|
+
console.log(chalk.gray(' No materials found\n'));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(chalk.bold('\n📦 Material List\n'));
|
|
109
|
+
|
|
110
|
+
const table = new Table({
|
|
111
|
+
head: [chalk.bold('ID'), chalk.bold('Code'), chalk.bold('No'), chalk.bold('Name'), chalk.bold('Class'), chalk.bold('Status')],
|
|
112
|
+
colWidths: [14, 14, 14, 30, 16, 10],
|
|
113
|
+
style: {
|
|
114
|
+
head: [],
|
|
115
|
+
border: [],
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
for (const material of records) {
|
|
120
|
+
const statusText = material.statusFlag === 1 ? chalk.green('Enable') : chalk.red('Disable');
|
|
121
|
+
table.push([
|
|
122
|
+
material.materialId,
|
|
123
|
+
material.materialCode || '-',
|
|
124
|
+
material.materialNo || '-',
|
|
125
|
+
material.materialName || '-',
|
|
126
|
+
material.materialClass || '-',
|
|
127
|
+
statusText,
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
console.log(table.toString());
|
|
132
|
+
console.log();
|
|
133
|
+
console.log(
|
|
134
|
+
chalk.gray(
|
|
135
|
+
` Total: ${data.totalRows} | Page: ${data.pageNo + 1} / ${Math.ceil(data.totalRows / data.pageSize) || 1} | Size: ${data.pageSize}`
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
console.log();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return listCommand;
|
|
142
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 { Material, MaterialRequest } from '../../../types/material.js';
|
|
7
|
+
|
|
8
|
+
export function createMaterialUpdateCommand(): Command {
|
|
9
|
+
const updateCommand = new Command('update');
|
|
10
|
+
updateCommand
|
|
11
|
+
.description('Update material information')
|
|
12
|
+
.argument('<materialId>', 'Material ID')
|
|
13
|
+
.option('-n, --name <name>', 'Material name')
|
|
14
|
+
.option('-c, --class <class>', 'Material class')
|
|
15
|
+
.option('--type <type>', 'Material type')
|
|
16
|
+
.option('--unit <unit>', 'Material unit')
|
|
17
|
+
.option('--dry-run', 'Preview changes without making API call')
|
|
18
|
+
.option('--json', 'Output result as JSON')
|
|
19
|
+
.action(async (materialId: string, options: Record<string, unknown>) => {
|
|
20
|
+
const context = configManager.getCurrentContext();
|
|
21
|
+
const environment = context.environment as Environment;
|
|
22
|
+
const tenant = context.tenant;
|
|
23
|
+
|
|
24
|
+
const fields: Partial<MaterialRequest> = {};
|
|
25
|
+
if (options.name) fields.materialName = options.name as string;
|
|
26
|
+
if (options.class) fields.materialClass = options.class as string;
|
|
27
|
+
if (options.type) fields.materialType = options.type as string;
|
|
28
|
+
if (options.unit) fields.materialUnit = options.unit as string;
|
|
29
|
+
|
|
30
|
+
const providedFields = Object.keys(fields).filter(
|
|
31
|
+
(k) => fields[k as keyof MaterialRequest] !== undefined
|
|
32
|
+
);
|
|
33
|
+
if (providedFields.length === 0) {
|
|
34
|
+
console.error(
|
|
35
|
+
chalk.red('\n✗ No fields to update. Provide at least one of: --name, --class, --type, --unit\n')
|
|
36
|
+
);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (options.dryRun) {
|
|
41
|
+
console.log(chalk.bold(`\n📦 Update Material — Dry Run (${environment})\n`));
|
|
42
|
+
console.log(chalk.gray(` Material ID: ${materialId}`));
|
|
43
|
+
console.log(chalk.gray('\n Changes to be applied:'));
|
|
44
|
+
for (const field of providedFields) {
|
|
45
|
+
const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
|
|
46
|
+
console.log(chalk.cyan(` ${label}: "${fields[field as keyof MaterialRequest]}"`));
|
|
47
|
+
}
|
|
48
|
+
console.log();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let currentMaterial: Material | undefined;
|
|
53
|
+
try {
|
|
54
|
+
const materialResponse = await apiClient.getMaterial(environment, tenant, materialId);
|
|
55
|
+
if (!materialResponse.success || !materialResponse.data) {
|
|
56
|
+
console.error(chalk.red(`\n✗ Material not found: ${materialId}`));
|
|
57
|
+
if (materialResponse.error?.message) {
|
|
58
|
+
console.error(chalk.gray(` ${materialResponse.error.message}`));
|
|
59
|
+
}
|
|
60
|
+
if (materialResponse.error?.code) {
|
|
61
|
+
console.error(chalk.gray(` Error code: ${materialResponse.error.code}`));
|
|
62
|
+
}
|
|
63
|
+
console.error();
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
currentMaterial = materialResponse.data as Material;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(chalk.red(`\n✗ Failed to fetch material: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
(options as any).json = process.argv.includes('--json');
|
|
74
|
+
const outputJson = (options as Record<string, unknown>).json === true;
|
|
75
|
+
|
|
76
|
+
console.log(chalk.bold(`\n📦 Update Material (${environment})\n`));
|
|
77
|
+
console.log(chalk.gray(` Material ID: ${materialId}`));
|
|
78
|
+
console.log(chalk.gray(` Current Name: ${currentMaterial.materialName}`));
|
|
79
|
+
console.log(chalk.gray('\n Changes:'));
|
|
80
|
+
for (const field of providedFields) {
|
|
81
|
+
const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
|
|
82
|
+
const currentVal = (currentMaterial as unknown as Record<string, unknown>)[field] ?? '(not set)';
|
|
83
|
+
const newVal = fields[field as keyof MaterialRequest];
|
|
84
|
+
console.log(chalk.cyan(` ${label}: "${currentVal}" → "${newVal}"`));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const updateData = { materialId, ...fields } as MaterialRequest;
|
|
88
|
+
try {
|
|
89
|
+
const response = await apiClient.updateMaterial(environment, tenant, materialId, updateData);
|
|
90
|
+
|
|
91
|
+
if (response.success) {
|
|
92
|
+
if (outputJson) {
|
|
93
|
+
console.log(JSON.stringify({ success: true, data: response.data }, null, 2));
|
|
94
|
+
} else {
|
|
95
|
+
console.log(chalk.green(`\n✓ Material updated successfully\n`));
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
if (outputJson) {
|
|
99
|
+
console.log(JSON.stringify({ success: false, error: response.error }, null, 2));
|
|
100
|
+
} else {
|
|
101
|
+
console.error(chalk.red(`\n✗ Update failed: ${response.error?.message || 'Unknown error'}`));
|
|
102
|
+
if (response.error?.code) {
|
|
103
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
104
|
+
}
|
|
105
|
+
console.error();
|
|
106
|
+
}
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (outputJson) {
|
|
111
|
+
console.log(
|
|
112
|
+
JSON.stringify({
|
|
113
|
+
success: false,
|
|
114
|
+
error: { message: error instanceof Error ? error.message : 'Unknown error' },
|
|
115
|
+
})
|
|
116
|
+
);
|
|
117
|
+
} else {
|
|
118
|
+
console.error(chalk.red(`\n✗ Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
119
|
+
}
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return updateCommand;
|
|
125
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
6
|
+
import { CreateSupplierRequest } from '../../../types/supplier.js';
|
|
7
|
+
|
|
8
|
+
function formatTable(data: CreateSupplierRequest): string {
|
|
9
|
+
const lines: string[] = [];
|
|
10
|
+
lines.push(` ${chalk.gray('Name:')} ${data.supplierName || '(not set)'}`);
|
|
11
|
+
lines.push(` ${chalk.gray('Code:')} ${data.supplierCode}`);
|
|
12
|
+
if (data.supplierType) lines.push(` ${chalk.gray('Type:')} ${data.supplierType}`);
|
|
13
|
+
if (data.contactPerson) lines.push(` ${chalk.gray('Contact:')} ${data.contactPerson}`);
|
|
14
|
+
if (data.contactPhone) lines.push(` ${chalk.gray('Phone:')} ${data.contactPhone}`);
|
|
15
|
+
if (data.address) lines.push(` ${chalk.gray('Address:')} ${data.address}`);
|
|
16
|
+
return lines.join('\n');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createSupplierCreateCommand(): Command {
|
|
20
|
+
const cmd = new Command('create');
|
|
21
|
+
cmd.description('Create a new supplier (auto-generates supplier code)');
|
|
22
|
+
|
|
23
|
+
cmd
|
|
24
|
+
.option('-n, --name <name>', 'Supplier name (required)')
|
|
25
|
+
.option('-c, --code <code>', 'Supplier code (auto-generated if not provided)')
|
|
26
|
+
.option('-t, --type <type>', 'Supplier type')
|
|
27
|
+
.option('--contact <contact>', 'Contact person')
|
|
28
|
+
.option('-p, --phone <phone>', 'Contact phone')
|
|
29
|
+
.option('-a, --address <address>', 'Address')
|
|
30
|
+
.option('--dry-run', 'Preview without making API call')
|
|
31
|
+
.option('--json', 'Output as JSON');
|
|
32
|
+
|
|
33
|
+
cmd.action(async () => {
|
|
34
|
+
const context = configManager.getCurrentContext();
|
|
35
|
+
const opts = cmd.opts();
|
|
36
|
+
|
|
37
|
+
let name = opts.name as string | undefined;
|
|
38
|
+
let code = opts.code as string | undefined;
|
|
39
|
+
const type = opts.type as string | undefined;
|
|
40
|
+
const contact = opts.contact as string | undefined;
|
|
41
|
+
const phone = opts.phone as string | undefined;
|
|
42
|
+
const address = opts.address as string | undefined;
|
|
43
|
+
const dryRun = opts.dryRun === true;
|
|
44
|
+
const jsonOutput = opts.json === true;
|
|
45
|
+
|
|
46
|
+
if (!name) {
|
|
47
|
+
const { inputName } = await inquirer.prompt([
|
|
48
|
+
{
|
|
49
|
+
type: 'input',
|
|
50
|
+
name: 'inputName',
|
|
51
|
+
message: 'Enter supplier name:',
|
|
52
|
+
validate: (input: string) => input.trim().length > 0 || 'Supplier name is required',
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
55
|
+
name = inputName;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!code) {
|
|
59
|
+
const codeResponse = await apiClient.getCodeByType(context.environment, context.tenant, 'TenantSupplierCode');
|
|
60
|
+
if (codeResponse.success && codeResponse.data) {
|
|
61
|
+
code = codeResponse.data;
|
|
62
|
+
} else {
|
|
63
|
+
const errMsg = codeResponse.error?.message || 'Failed to generate supplier code';
|
|
64
|
+
if (jsonOutput) {
|
|
65
|
+
console.log(JSON.stringify({ success: false, error: { code: 'CODE_GENERATION_ERROR', message: errMsg } }));
|
|
66
|
+
} else {
|
|
67
|
+
console.error(chalk.red(`\n✗ Failed to generate supplier code: ${errMsg}\n`));
|
|
68
|
+
}
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const data: CreateSupplierRequest = {
|
|
74
|
+
supplierName: name,
|
|
75
|
+
supplierCode: code!,
|
|
76
|
+
supplierType: type,
|
|
77
|
+
contactPerson: contact,
|
|
78
|
+
contactPhone: phone,
|
|
79
|
+
address: address,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (dryRun) {
|
|
83
|
+
if (jsonOutput) {
|
|
84
|
+
console.log(JSON.stringify({ success: true, dryRun: true, data }));
|
|
85
|
+
} else {
|
|
86
|
+
console.log(chalk.bold('\n🔍 Dry-Run Mode: No changes will be made\n'));
|
|
87
|
+
console.log(' Supplier to be created:');
|
|
88
|
+
console.log(formatTable(data));
|
|
89
|
+
console.log();
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!jsonOutput) {
|
|
95
|
+
console.log(chalk.bold('\n📝 Creating Supplier\n'));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const response = await apiClient.createSupplier(context.environment, context.tenant, data);
|
|
99
|
+
|
|
100
|
+
if (!response.success) {
|
|
101
|
+
const errorMsg = response.error?.message || 'Failed to create supplier';
|
|
102
|
+
const errorCode = response.error?.code || 'CREATE_SUPPLIER_ERROR';
|
|
103
|
+
if (jsonOutput) {
|
|
104
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
105
|
+
} else {
|
|
106
|
+
console.error(chalk.red(`\n✗ Failed to create supplier: ${errorMsg}`));
|
|
107
|
+
if (response.error?.code) {
|
|
108
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
109
|
+
}
|
|
110
|
+
console.error();
|
|
111
|
+
}
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (response.success) {
|
|
116
|
+
const supplier = response.data as {
|
|
117
|
+
supplierId?: number;
|
|
118
|
+
supplierCode?: string;
|
|
119
|
+
supplierName?: string;
|
|
120
|
+
supplierType?: string;
|
|
121
|
+
contactPerson?: string;
|
|
122
|
+
contactPhone?: string;
|
|
123
|
+
address?: string;
|
|
124
|
+
statusFlag?: number;
|
|
125
|
+
createTime?: string;
|
|
126
|
+
} | undefined;
|
|
127
|
+
|
|
128
|
+
if (jsonOutput) {
|
|
129
|
+
console.log(JSON.stringify({ success: true, data: supplier }));
|
|
130
|
+
} else {
|
|
131
|
+
console.log(chalk.green('✓ Supplier created successfully\n'));
|
|
132
|
+
if (supplier?.supplierId) console.log(` ${chalk.gray('Supplier ID:')} ${chalk.green(String(supplier.supplierId))}`);
|
|
133
|
+
if (supplier?.supplierName) console.log(` ${chalk.gray('Name:')} ${supplier.supplierName}`);
|
|
134
|
+
if (supplier?.supplierCode) console.log(` ${chalk.gray('Code:')} ${supplier.supplierCode}`);
|
|
135
|
+
if (supplier?.supplierType) console.log(` ${chalk.gray('Type:')} ${supplier.supplierType}`);
|
|
136
|
+
if (supplier?.contactPerson) console.log(` ${chalk.gray('Contact:')} ${supplier.contactPerson}`);
|
|
137
|
+
if (supplier?.contactPhone) console.log(` ${chalk.gray('Phone:')} ${supplier.contactPhone}`);
|
|
138
|
+
if (supplier?.address) console.log(` ${chalk.gray('Address:')} ${supplier.address}`);
|
|
139
|
+
if (supplier?.statusFlag !== undefined) {
|
|
140
|
+
const statusText = supplier.statusFlag === 1 ? 'Enabled' : 'Disabled';
|
|
141
|
+
console.log(` ${chalk.gray('Status:')} ${chalk.green(statusText)}`);
|
|
142
|
+
}
|
|
143
|
+
console.log();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return cmd;
|
|
149
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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 { Supplier } from '../../../types/supplier.js';
|
|
7
|
+
|
|
8
|
+
export function createSupplierDeleteCommand(): Command {
|
|
9
|
+
const deleteCommand = new Command('delete');
|
|
10
|
+
deleteCommand
|
|
11
|
+
.description('Delete a supplier')
|
|
12
|
+
.argument('<supplierId>', 'Supplier ID')
|
|
13
|
+
.option('--force', 'Skip confirmation and delete directly')
|
|
14
|
+
.option('--json', 'Output as JSON')
|
|
15
|
+
.action(async (supplierId: string, options: Record<string, unknown>) => {
|
|
16
|
+
const context = configManager.getCurrentContext();
|
|
17
|
+
const environment = context.environment as Environment;
|
|
18
|
+
const tenant = context.tenant;
|
|
19
|
+
const jsonOutput = options.json === true;
|
|
20
|
+
|
|
21
|
+
if (!jsonOutput) {
|
|
22
|
+
console.log(chalk.bold(`\n🗑️ Delete Supplier (${environment})\n`));
|
|
23
|
+
console.log(chalk.gray(` Supplier ID: ${supplierId}`));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let supplier: Supplier | undefined;
|
|
27
|
+
try {
|
|
28
|
+
const supplierResponse = await apiClient.getSupplier(environment, tenant, supplierId);
|
|
29
|
+
if (!supplierResponse.success || !supplierResponse.data || !('supplierId' in supplierResponse.data)) {
|
|
30
|
+
const errMsg = `Supplier not found: ${supplierId}`;
|
|
31
|
+
if (jsonOutput) {
|
|
32
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
33
|
+
} else {
|
|
34
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
35
|
+
}
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
supplier = supplierResponse.data as Supplier;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
41
|
+
if (jsonOutput) {
|
|
42
|
+
console.log(JSON.stringify({ success: false, error: { code: 'FETCH_ERROR', message: `Failed to fetch supplier: ${errMsg}` } }));
|
|
43
|
+
} else {
|
|
44
|
+
console.error(chalk.red(`\n✗ Failed to fetch supplier: ${errMsg}\n`));
|
|
45
|
+
}
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!jsonOutput) {
|
|
50
|
+
console.log(chalk.gray(` Name: ${supplier.supplierName}`));
|
|
51
|
+
console.log(chalk.gray(` Code: ${supplier.supplierCode}`));
|
|
52
|
+
if (supplier.contactPerson) {
|
|
53
|
+
console.log(chalk.gray(` Contact: ${supplier.contactPerson} (${supplier.contactPhone || 'N/A'})`));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!options.force) {
|
|
58
|
+
if (jsonOutput) {
|
|
59
|
+
console.log(JSON.stringify({ success: true, dryRun: true, supplier }));
|
|
60
|
+
} else {
|
|
61
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual deletion will be made\n'));
|
|
62
|
+
console.log(chalk.yellow(' To delete, add: --force\n'));
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const response = await apiClient.deleteSupplier(environment, tenant, supplierId);
|
|
69
|
+
|
|
70
|
+
if (response.success) {
|
|
71
|
+
if (jsonOutput) {
|
|
72
|
+
console.log(JSON.stringify({ success: true, supplierId, name: supplier.supplierName }));
|
|
73
|
+
} else {
|
|
74
|
+
console.log(chalk.green(`\n✓ Supplier "${supplier.supplierName}" (ID: ${supplierId}) deleted\n`));
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
78
|
+
const errorCode = response.error?.code || 'DELETE_ERROR';
|
|
79
|
+
if (jsonOutput) {
|
|
80
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
81
|
+
} else {
|
|
82
|
+
console.error(chalk.red(`\n✗ Failed to delete supplier: ${errorMsg}`));
|
|
83
|
+
if (response.error?.code) {
|
|
84
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
85
|
+
}
|
|
86
|
+
console.error();
|
|
87
|
+
}
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
92
|
+
if (jsonOutput) {
|
|
93
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
94
|
+
} else {
|
|
95
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
96
|
+
}
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return deleteCommand;
|
|
102
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
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 { Supplier } from '../../../types/supplier.js';
|
|
8
|
+
|
|
9
|
+
export function createSupplierDisableCommand(): Command {
|
|
10
|
+
const disableCommand = new Command('disable');
|
|
11
|
+
disableCommand
|
|
12
|
+
.description('Disable (deactivate) a supplier')
|
|
13
|
+
.argument('<supplierId>', 'Supplier ID')
|
|
14
|
+
.option('--force', 'Skip confirmation prompt')
|
|
15
|
+
.option('--dry-run', 'Preview the operation without executing')
|
|
16
|
+
.option('--json', 'Output as JSON')
|
|
17
|
+
.action(async (supplierId: string, options: Record<string, unknown>) => {
|
|
18
|
+
const context = configManager.getCurrentContext();
|
|
19
|
+
const environment = context.environment as Environment;
|
|
20
|
+
const tenant = context.tenant;
|
|
21
|
+
const force = options.force === true;
|
|
22
|
+
const dryRun = options.dryRun === true;
|
|
23
|
+
const jsonOutput = options.json === true;
|
|
24
|
+
|
|
25
|
+
if (!supplierId || supplierId.trim() === '') {
|
|
26
|
+
const errMsg = 'Invalid supplier ID';
|
|
27
|
+
if (jsonOutput) {
|
|
28
|
+
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_ID', message: errMsg } }));
|
|
29
|
+
} else {
|
|
30
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
31
|
+
}
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!jsonOutput) {
|
|
36
|
+
console.log(chalk.bold(`\n⬇ Disable Supplier (${environment})\n`));
|
|
37
|
+
console.log(chalk.gray(` Supplier ID: ${supplierId}`));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (dryRun) {
|
|
41
|
+
if (jsonOutput) {
|
|
42
|
+
console.log(JSON.stringify({ success: true, dryRun: true, message: 'No actual API call will be made' }));
|
|
43
|
+
} else {
|
|
44
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual API call will be made\n'));
|
|
45
|
+
console.log(chalk.gray(' This operation will disable the supplier.'));
|
|
46
|
+
console.log();
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let supplier: Supplier | undefined;
|
|
52
|
+
try {
|
|
53
|
+
const supplierResponse = await apiClient.getSupplier(environment, tenant, supplierId);
|
|
54
|
+
if (!supplierResponse.success || !supplierResponse.data || !('supplierId' in supplierResponse.data)) {
|
|
55
|
+
const errMsg = `Supplier not found: ${supplierId}`;
|
|
56
|
+
if (jsonOutput) {
|
|
57
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
58
|
+
} else {
|
|
59
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
60
|
+
}
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
supplier = supplierResponse.data as Supplier;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
66
|
+
const jsonErr = { success: false, error: { code: 'FETCH_ERROR', message: 'Failed to fetch supplier: ' + errMsg } };
|
|
67
|
+
if (jsonOutput) {
|
|
68
|
+
console.log(JSON.stringify(jsonErr));
|
|
69
|
+
} else {
|
|
70
|
+
console.error(chalk.red(`\n✗ Failed to fetch supplier: ${errMsg}\n`));
|
|
71
|
+
}
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (supplier.statusFlag === 2) {
|
|
76
|
+
const errMsg = `Supplier "${supplier.supplierName}" is already disabled`;
|
|
77
|
+
if (jsonOutput) {
|
|
78
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ALREADY_DISABLED', message: errMsg } }));
|
|
79
|
+
} else {
|
|
80
|
+
console.error(chalk.yellow(`\n⚠ ${errMsg}\n`));
|
|
81
|
+
}
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!force) {
|
|
86
|
+
if (!jsonOutput) {
|
|
87
|
+
console.log(chalk.gray(` Name: ${supplier.supplierName}`));
|
|
88
|
+
console.log(chalk.gray(` Code: ${supplier.supplierCode}`));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const { confirm } = await inquirer.prompt([
|
|
92
|
+
{
|
|
93
|
+
type: 'confirm',
|
|
94
|
+
name: 'confirm',
|
|
95
|
+
message: `Disable supplier "${supplier.supplierName}"?`,
|
|
96
|
+
default: false,
|
|
97
|
+
},
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
if (!confirm) {
|
|
101
|
+
if (jsonOutput) {
|
|
102
|
+
console.log(JSON.stringify({ success: false, error: { code: 'CANCELLED', message: 'Operation cancelled' } }));
|
|
103
|
+
} else {
|
|
104
|
+
console.log(chalk.gray('\n Operation cancelled.\n'));
|
|
105
|
+
}
|
|
106
|
+
process.exit(0);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const response = await apiClient.disableSupplier(environment, tenant, supplierId);
|
|
112
|
+
|
|
113
|
+
if (response.success) {
|
|
114
|
+
if (jsonOutput) {
|
|
115
|
+
console.log(JSON.stringify({ success: true, supplierId, name: supplier?.supplierName }));
|
|
116
|
+
} else {
|
|
117
|
+
console.log(chalk.green(`\n✓ Supplier ${supplier?.supplierName || supplierId} disabled\n`));
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
121
|
+
const errorCode = response.error?.code || 'DISABLE_ERROR';
|
|
122
|
+
if (jsonOutput) {
|
|
123
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
124
|
+
} else {
|
|
125
|
+
console.error(chalk.red(`\n✗ Failed to disable supplier: ${errorMsg}`));
|
|
126
|
+
if (response.error?.code) {
|
|
127
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
128
|
+
}
|
|
129
|
+
console.error();
|
|
130
|
+
}
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
135
|
+
if (jsonOutput) {
|
|
136
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
137
|
+
} else {
|
|
138
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
139
|
+
}
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return disableCommand;
|
|
145
|
+
}
|