disallow empty new warnings

This commit is contained in:
Michael C
2023-09-27 15:09:35 -04:00
parent ad666ff487
commit 1b5a079bbd
2 changed files with 51 additions and 11 deletions

View File

@@ -47,6 +47,9 @@ export async function postWarning(req: Request, res: Response): Promise<Response
const previousWarning = await db.prepare("get", 'SELECT * FROM "warnings" WHERE "userID" = ? AND "issuerUserID" = ? AND "type" = ?', [userID, issuerUserID, type]) as warningEntry;
if (!previousWarning) {
if (!reason) {
return res.status(400).json({ "message": "Missing warning reason" });
}
await db.prepare(
"run",
'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled", "reason", "type") VALUES (?, ?, ?, 1, ?, ?)',