51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
|
|
const db = require('./db');
|
||
|
|
|
||
|
|
const logHostResult = async (data) => {
|
||
|
|
const query = `
|
||
|
|
INSERT INTO upgrade_log (
|
||
|
|
uuid, start_time, roomtype_id, host_str, filename, status,
|
||
|
|
end_time, file_type, config_version, firmware_version
|
||
|
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||
|
|
`;
|
||
|
|
const values = [
|
||
|
|
data.uuid,
|
||
|
|
data.start_time,
|
||
|
|
data.roomtype_id,
|
||
|
|
data.host_str,
|
||
|
|
data.filename,
|
||
|
|
data.status,
|
||
|
|
data.end_time,
|
||
|
|
data.file_type,
|
||
|
|
data.config_version,
|
||
|
|
data.firmware_version
|
||
|
|
];
|
||
|
|
await db.query(query, values);
|
||
|
|
};
|
||
|
|
|
||
|
|
const getUpgradeState = async (key) => {
|
||
|
|
const res = await db.query('SELECT * FROM upgrade_state WHERE state_key = $1', [key]);
|
||
|
|
if (res.rows.length > 0) {
|
||
|
|
return res.rows[0];
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
};
|
||
|
|
|
||
|
|
const updateUpgradeState = async (key, currentRoomtypeIndex, executionCount) => {
|
||
|
|
const query = `
|
||
|
|
INSERT INTO upgrade_state (state_key, current_roomtype_index, execution_count, last_updated)
|
||
|
|
VALUES ($1, $2, $3, NOW())
|
||
|
|
ON CONFLICT (state_key)
|
||
|
|
DO UPDATE SET
|
||
|
|
current_roomtype_index = EXCLUDED.current_roomtype_index,
|
||
|
|
execution_count = EXCLUDED.execution_count,
|
||
|
|
last_updated = NOW();
|
||
|
|
`;
|
||
|
|
await db.query(query, [key, currentRoomtypeIndex, executionCount]);
|
||
|
|
};
|
||
|
|
|
||
|
|
module.exports = {
|
||
|
|
logHostResult,
|
||
|
|
getUpgradeState,
|
||
|
|
updateUpgradeState
|
||
|
|
};
|