Improve validation and error handling on form field

This commit is contained in:
Burak Arslan committed 2025-08-06 00:53:35 +03:00
1 parent 0ea3379397
commit 4c2c452b91
9 files changed
+35 -13

No files matched your search

+2
View File
@@ -31,6 +31,7 @@ const { compile } = pkg;
import mjml2html from "mjml";
import jwt from "jsonwebtoken";
import crypto from "crypto";
import { games } from "gamedig";
import { fileURLToPath } from "url";
import { ObjectId } from "mongodb";
@@ -201,6 +202,7 @@ export const initializeServices = async ({ logger, envSettings, settingsService
papaparse,
logger,
errorService,
games,
});
const services = {
+1 -2
View File
@@ -15,7 +15,6 @@ import {
import sslChecker from "ssl-checker";
import { fetchMonitorCertificate } from "./controllerUtils.js";
import BaseController from "./baseController.js";
import { games } from "gamedig";
const SERVICE_NAME = "monitorController";
class MonitorController extends BaseController {
@@ -447,7 +446,7 @@ class MonitorController extends BaseController {
async (req, res) => {
return res.success({
msg: "OK",
data: games,
data: this.monitorService.getAllGames(),
});
},
SERVICE_NAME,
+1 -3
View File
@@ -25,9 +25,6 @@ class MonitorRoutes {
// Hardware routes
this.router.get("/hardware/details/:monitorId", this.monitorController.getHardwareDetailsById);
// Game routes
this.router.get("/games", this.monitorController.getAllGames);
// General monitor routes
this.router.post("/pause/:monitorId", isAllowed(["admin", "superadmin"]), this.monitorController.pauseMonitor);
this.router.get("/stats/:monitorId", this.monitorController.getMonitorStatsById);
@@ -47,6 +44,7 @@ class MonitorRoutes {
this.router.get("/export", isAllowed(["admin", "superadmin"]), this.monitorController.exportMonitorsToCSV);
this.router.post("/bulk", isAllowed(["admin", "superadmin"]), upload.single("csvFile"), this.monitorController.createBulkMonitors);
this.router.post("/test-email", isAllowed(["admin", "superadmin"]), this.monitorController.sendTestEmail);
this.router.get("/games", this.monitorController.getAllGames);
// Individual monitor CRUD routes
this.router.get("/:monitorId", this.monitorController.getMonitorById);
@@ -4,7 +4,7 @@ const SERVICE_NAME = "MonitorService";
class MonitorService {
static SERVICE_NAME = SERVICE_NAME;
constructor({ db, settingsService, jobQueue, stringService, emailService, papaparse, logger, errorService }) {
constructor({ db, settingsService, jobQueue, stringService, emailService, papaparse, logger, errorService, games }) {
this.db = db;
this.settingsService = settingsService;
this.jobQueue = jobQueue;
@@ -13,6 +13,7 @@ class MonitorService {
this.papaparse = papaparse;
this.logger = logger;
this.errorService = errorService;
this.games = games;
}
get serviceName() {
@@ -262,6 +263,10 @@ class MonitorService {
const csv = this.papaparse.unparse(csvData);
return csv;
};
getAllGames = () => {
return this.games;
};
}
export default MonitorService;
@@ -503,7 +503,7 @@ class NetworkService {
host: url,
port: port,
}).catch((error) => {
return false;
null;
});
if (!state) {
+1 -1
View File
@@ -171,7 +171,7 @@ const createMonitorBodyValidation = joi.object({
jsonPath: joi.string().allow(""),
expectedValue: joi.string().allow(""),
matchMethod: joi.string(),
gameId: joi.string(),
gameId: joi.string().allow(""),
});
const createMonitorsBodyValidation = joi.array().items(