feat: CPU, GPU, RAM 입력 시 부품 마스터 기준 정합성 검증 추가 및 기존 데이터 정제

This commit is contained in:
이태훈
2026-06-25 13:41:31 +09:00
parent 1ecee53966
commit 6ed939c6bf
2 changed files with 45 additions and 0 deletions

View File

@@ -261,6 +261,30 @@ app.post('/api/asset/:category/save', async (req, res) => {
connection = await pool.getConnection();
await connection.beginTransaction();
// 3.0.0 CPU, GPU, RAM 부품 마스터 유효성 검사
const partsToCheck = [
{ value: asset.cpu, category: 'CPU', label: 'CPU' },
{ value: asset.gpu, category: 'GPU', label: 'GPU' },
{ value: asset.ram, category: 'RAM', label: 'RAM' }
];
for (const part of partsToCheck) {
const val = String(part.value || '').trim();
if (val) {
const [rows] = await connection.query(
'SELECT id FROM hardware_components_master WHERE UPPER(category) = ? AND LOWER(TRIM(component_name)) = ?',
[part.category, val.toLowerCase()]
);
if (rows.length === 0) {
await connection.rollback();
return res.status(400).json({
success: false,
message: `입력하신 ${part.label} "${val}"은(는) 부품 마스터에 존재하지 않는 규격입니다.`
});
}
}
}
// 3.0 History Tracking & Auto Field Update
const [oldCoreRows] = await connection.query('SELECT * FROM asset_core WHERE id = ?', [asset.id]);
const [oldSpecRows] = await connection.query('SELECT * FROM asset_spec WHERE asset_id = ?', [asset.id]);

View File

@@ -454,6 +454,27 @@ class HwAssetModal extends BaseModal {
formData.forEach((value, key) => { if (key !== 'id') updated[key] = value; });
updated.location = bldgSelect.value;
// 부품 마스터 기준 정합성 검증 (CPU, GPU, RAM)
const checkFields = [
{ name: 'cpu', label: 'CPU', category: 'CPU' },
{ name: 'gpu', label: 'GPU', category: 'GPU' },
{ name: 'ram', label: 'RAM', category: 'RAM' }
];
for (const field of checkFields) {
const value = String(updated[field.name] || '').trim();
if (value) {
const isExists = this.masterComponents.some(c =>
c.category.toUpperCase() === field.category &&
c.component_name.trim().toLowerCase() === value.toLowerCase()
);
if (!isExists) {
alert(`입력하신 ${field.label} "${value}"은(는) 부품 마스터에 등록되지 않은 규격입니다. 자동완성 목록에서 선택하거나 부품마스터에 먼저 등록해 주세요.`);
return;
}
}
}
if (await saveAsset(this.getCategoryKey(updated), updated)) {
alert(UI_TEXT.MESSAGES.SAVE_SUCCESS);
onSave(); this.close(); closeModals();