refactor: add color and name parameters to saveMiningArea and implement updateMiningArea function
This commit is contained in:
@@ -410,16 +410,17 @@ export function getAllTasks(status = null) {
|
||||
}
|
||||
|
||||
// Mining Areas
|
||||
export function saveMiningArea(turtleId, bounds, areaName = null, status = 'planned') {
|
||||
export function saveMiningArea(turtleId, bounds, areaName = null, status = 'planned', color = '#4a8c2a') {
|
||||
const stmt = db.prepare(`
|
||||
INSERT INTO mining_areas (turtle_id, min_x, min_y, min_z, max_x, max_y, max_z, status, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO mining_areas (turtle_id, min_x, min_y, min_z, max_x, max_y, max_z, name, color, status, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
const now = Date.now();
|
||||
const result = stmt.run(
|
||||
turtleId,
|
||||
bounds.minX, bounds.minY, bounds.minZ,
|
||||
bounds.maxX, bounds.maxY, bounds.maxZ,
|
||||
areaName, color,
|
||||
status, now, now
|
||||
);
|
||||
return result.lastInsertRowid;
|
||||
@@ -439,6 +440,24 @@ export function updateMiningAreaStatus(areaId, status) {
|
||||
stmt.run(status, Date.now(), areaId);
|
||||
}
|
||||
|
||||
export function updateMiningArea(areaId, updates) {
|
||||
const allowedFields = ['name', 'color', 'status', 'min_x', 'min_y', 'min_z', 'max_x', 'max_y', 'max_z', 'turtle_id'];
|
||||
const setClauses = [];
|
||||
const values = [];
|
||||
for (const [key, value] of Object.entries(updates)) {
|
||||
if (allowedFields.includes(key)) {
|
||||
setClauses.push(`${key} = ?`);
|
||||
values.push(value);
|
||||
}
|
||||
}
|
||||
if (setClauses.length === 0) return;
|
||||
setClauses.push('updated_at = ?');
|
||||
values.push(Date.now());
|
||||
values.push(areaId);
|
||||
const stmt = db.prepare(`UPDATE mining_areas SET ${setClauses.join(', ')} WHERE id = ?`);
|
||||
stmt.run(...values);
|
||||
}
|
||||
|
||||
export function deleteMiningArea(areaId) {
|
||||
const stmt = db.prepare('DELETE FROM mining_areas WHERE id = ?');
|
||||
return stmt.run(areaId);
|
||||
|
||||
Reference in New Issue
Block a user