refactor: standardize modal system, unify hardware DB schemas, and implement automatic asset reclassification
This commit is contained in:
@@ -6,6 +6,7 @@ export interface MasterAssetData {
|
||||
server: HardwareAsset[];
|
||||
storage: HardwareAsset[];
|
||||
equip: HardwareAsset[];
|
||||
mobile: HardwareAsset[];
|
||||
subSw: SoftwareAsset[];
|
||||
permSw: SoftwareAsset[];
|
||||
swUsers: SWUser[];
|
||||
@@ -27,6 +28,7 @@ export const state: AppState = {
|
||||
server: [],
|
||||
storage: [],
|
||||
equip: [],
|
||||
mobile: [],
|
||||
subSw: [],
|
||||
permSw: [],
|
||||
swUsers: [],
|
||||
@@ -44,6 +46,7 @@ export async function loadMasterDataFromDB() {
|
||||
{ key: 'server', url: 'http://localhost:3000/api/server' },
|
||||
{ key: 'storage', url: 'http://localhost:3000/api/storage' },
|
||||
{ key: 'equip', url: 'http://localhost:3000/api/equip' },
|
||||
{ key: 'mobile', url: 'http://localhost:3000/api/mobile' },
|
||||
{ key: 'subSw', url: 'http://localhost:3000/api/sw/sub' },
|
||||
{ key: 'permSw', url: 'http://localhost:3000/api/sw/perm' },
|
||||
{ key: 'swUsers', url: 'http://localhost:3000/api/sw-users' }
|
||||
@@ -70,3 +73,46 @@ export async function loadMasterDataFromDB() {
|
||||
export function updateState(newState: Partial<AppState>) {
|
||||
Object.assign(state, newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* 하드웨어 자산 통합 저장 (자동 카테고리 분류)
|
||||
*/
|
||||
export function saveHardwareAsset(updatedAsset: HardwareAsset) {
|
||||
const { type } = updatedAsset;
|
||||
const detailPurpose = (updatedAsset as any).상세용도 || '';
|
||||
|
||||
// 1. 타겟 카테고리 결정
|
||||
let targetKey: keyof MasterAssetData = 'equip';
|
||||
if (type === '서버' || (type === 'PC' && detailPurpose === '서버')) targetKey = 'server';
|
||||
else if (['NAS', 'DAS', '스토리지'].includes(type)) targetKey = 'storage';
|
||||
else if (['CPU', 'GPU', 'RAM', 'HDD'].includes(type)) targetKey = 'equip';
|
||||
else if (['모바일', '태블릿', '노트북'].includes(type)) targetKey = 'mobile';
|
||||
else if (type === 'PC' && detailPurpose === '개인PC') targetKey = 'pc';
|
||||
|
||||
// 2. 모든 카테고리에서 기존 ID 자산 삭제 (이동 가능성 대비)
|
||||
const hwKeys: (keyof MasterAssetData)[] = ['pc', 'server', 'storage', 'equip', 'mobile'];
|
||||
hwKeys.forEach(key => {
|
||||
const arr = state.masterData[key] as HardwareAsset[];
|
||||
if (Array.isArray(arr)) {
|
||||
const idx = arr.findIndex(a => a.id === updatedAsset.id);
|
||||
if (idx > -1) arr.splice(idx, 1);
|
||||
}
|
||||
});
|
||||
|
||||
// 3. 새로운 타겟 카테고리에 추가
|
||||
(state.masterData[targetKey] as HardwareAsset[]).push(updatedAsset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 하드웨어 자산 통합 삭제
|
||||
*/
|
||||
export function deleteHardwareAsset(assetId: string) {
|
||||
const hwKeys: (keyof MasterAssetData)[] = ['pc', 'server', 'storage', 'equip', 'mobile'];
|
||||
hwKeys.forEach(key => {
|
||||
const arr = state.masterData[key] as HardwareAsset[];
|
||||
if (Array.isArray(arr)) {
|
||||
const idx = arr.findIndex(a => a.id === assetId);
|
||||
if (idx > -1) arr.splice(idx, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user