Add warning reason in postWarning

This commit is contained in:
Haidang666 2021-06-29 14:56:57 +07:00
parent 6f18a49ba0
commit 214ddc9807
3 changed files with 30 additions and 5 deletions

View file

@ -104,6 +104,7 @@
| issueTime | INTEGER | not null |
| issuerUserID | TEXT | not null |
| enabled | INTEGER | not null |
| reason | TEXT | not null, default '' |
| index | field |
| -- | :--: |

View file

@ -0,0 +1,19 @@
BEGIN TRANSACTION;
/* Add reason field */
CREATE TABLE "sqlb_temp_table_17" (
"userID" TEXT NOT NULL,
"issueTime" INTEGER NOT NULL,
"issuerUserID" TEXT NOT NULL,
enabled INTEGER NOT NULL,
"reason" TEXT NOT NULL default ''
);
INSERT INTO sqlb_temp_table_17 SELECT "userID","issueTime","issuerUserID","enabled", "" FROM "warnings";
DROP TABLE warnings;
ALTER TABLE sqlb_temp_table_17 RENAME TO "warnings";;
UPDATE "config" SET value = 17 WHERE key = 'version';
COMMIT;

View file

@ -7,10 +7,11 @@ import { HashedUserID, UserID } from '../types/user.model';
export async function postWarning(req: Request, res: Response) {
// Collect user input data
let issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
let userID: UserID = req.body.userID;
let issueTime = new Date().getTime();
let enabled: boolean = req.body.enabled ?? true;
const issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
const userID: UserID = req.body.userID;
const issueTime = new Date().getTime();
const enabled: boolean = req.body.enabled ?? true;
const reason: string = req.body.reason ?? '';
// Ensure user is a VIP
if (!await isUserVIP(issuerUserID)) {
@ -25,7 +26,11 @@ export async function postWarning(req: Request, res: Response) {
let previousWarning = await db.prepare('get', 'SELECT * FROM "warnings" WHERE "userID" = ? AND "issuerUserID" = ?', [userID, issuerUserID]);
if (!previousWarning) {
await db.prepare('run', 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES (?, ?, ?, 1)', [userID, issueTime, issuerUserID]);
await db.prepare(
'run',
'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled", "reason") VALUES (?, ?, ?, 1, ?)',
[userID, issueTime, issuerUserID, reason]
);
resultStatus = "issued to";
} else {
res.status(409).send();