Merge branch 'db_setting'
Some checks failed
ITAM Code Check / build-and-config-check (push) Successful in 21s
ITAM Docker Build Check / docker-build-check (push) Failing after 38s

This commit is contained in:
2026-06-19 16:26:16 +09:00
277 changed files with 2460 additions and 26769 deletions

View File

@@ -706,16 +706,41 @@ app.delete('/api/system-users/:id', async (req, res) => {
}
});
app.post('/api/maps/save', (req, res) => {
app.post('/api/maps/save', async (req, res) => {
let connection;
try {
const { path, boxes } = req.body;
if (!path) return res.status(400).json({ error: 'Path is required' });
let config = {};
if (fs.existsSync('map_config.json')) config = JSON.parse(fs.readFileSync('map_config.json', 'utf8') || '{}');
config[path] = boxes;
fs.writeFileSync('map_config.json', JSON.stringify(config, null, 2));
res.json({ success: true });
} catch (err) { handleError(res, err, 'SAVE MAPS'); }
// 1. Get old config to track movements
let oldConfig = {};
if (fs.existsSync('map_config.json')) {
oldConfig = JSON.parse(fs.readFileSync('map_config.json', 'utf8') || '{}');
}
const oldBoxes = oldConfig[path] || [];
// 2. Save new config to file
oldConfig[path] = boxes;
fs.writeFileSync('map_config.json', JSON.stringify(oldConfig, null, 2));
// 3. Sync Database Assets (asset_location table)
connection = await pool.getConnection();
for (const box of boxes) {
if (box.asset_id) {
console.log(`Syncing asset ${box.asset_id} to new position: [${box.x}, ${box.y}]`);
await connection.query(
'UPDATE asset_location SET loc_x = ?, loc_y = ? WHERE asset_id = ? AND is_active = 1',
[box.x, box.y, box.asset_id]
);
}
}
res.json({ success: true, message: 'Map and Database synced successfully' });
} catch (err) {
handleError(res, err, 'SAVE MAPS SYNC');
} finally {
if (connection) connection.release();
}
});
// 7. File Upload API (Base64)