Move maintenance code to maintenance-socket-handler.js

This commit is contained in:
Louis Lam 2022-09-17 16:58:08 +08:00
parent 7017c2e625
commit 120e578398
2 changed files with 27 additions and 27 deletions

View File

@ -767,30 +767,6 @@ let needSetup = false;
} }
}); });
socket.on("getMaintenance", async (maintenanceID, callback) => {
try {
checkLogin(socket);
console.log(`Get Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
let bean = await R.findOne("maintenance", " id = ? AND user_id = ? ", [
maintenanceID,
socket.userID,
]);
callback({
ok: true,
maintenance: await bean.toJSON(),
});
} catch (e) {
callback({
ok: false,
msg: e.message,
});
}
});
socket.on("getMonitorBeats", async (monitorID, period, callback) => { socket.on("getMonitorBeats", async (monitorID, period, callback) => {
try { try {
checkLogin(socket); checkLogin(socket);

View File

@ -139,6 +139,30 @@ module.exports.maintenanceSocketHandler = (socket) => {
} }
}); });
socket.on("getMaintenance", async (maintenanceID, callback) => {
try {
checkLogin(socket);
log.debug("maintenance", `Get Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
let bean = await R.findOne("maintenance", " id = ? AND user_id = ? ", [
maintenanceID,
socket.userID,
]);
callback({
ok: true,
maintenance: await bean.toJSON(),
});
} catch (e) {
callback({
ok: false,
msg: e.message,
});
}
});
socket.on("getMaintenanceList", async (callback) => { socket.on("getMaintenanceList", async (callback) => {
try { try {
checkLogin(socket); checkLogin(socket);
@ -159,7 +183,7 @@ module.exports.maintenanceSocketHandler = (socket) => {
try { try {
checkLogin(socket); checkLogin(socket);
console.log(`Get Monitors for Maintenance: ${maintenanceID} User ID: ${socket.userID}`); log.debug("maintenance", `Get Monitors for Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
let monitors = await R.getAll("SELECT monitor.id, monitor.name FROM monitor_maintenance mm JOIN monitor ON mm.monitor_id = monitor.id WHERE mm.maintenance_id = ? ", [ let monitors = await R.getAll("SELECT monitor.id, monitor.name FROM monitor_maintenance mm JOIN monitor ON mm.monitor_id = monitor.id WHERE mm.maintenance_id = ? ", [
maintenanceID, maintenanceID,
@ -183,7 +207,7 @@ module.exports.maintenanceSocketHandler = (socket) => {
try { try {
checkLogin(socket); checkLogin(socket);
console.log(`Get Status Pages for Maintenance: ${maintenanceID} User ID: ${socket.userID}`); log.debug("maintenance", `Get Status Pages for Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
let statusPages = await R.getAll("SELECT status_page.id, status_page.title FROM maintenance_status_page msp JOIN status_page ON msp.status_page_id = status_page.id WHERE msp.maintenance_id = ? ", [ let statusPages = await R.getAll("SELECT status_page.id, status_page.title FROM maintenance_status_page msp JOIN status_page ON msp.status_page_id = status_page.id WHERE msp.maintenance_id = ? ", [
maintenanceID, maintenanceID,
@ -207,7 +231,7 @@ module.exports.maintenanceSocketHandler = (socket) => {
try { try {
checkLogin(socket); checkLogin(socket);
console.log(`Delete Maintenance: ${maintenanceID} User ID: ${socket.userID}`); log.debug("maintenance", `Delete Maintenance: ${maintenanceID} User ID: ${socket.userID}`);
if (maintenanceID in server.maintenanceList) { if (maintenanceID in server.maintenanceList) {
delete server.maintenanceList[maintenanceID]; delete server.maintenanceList[maintenanceID];