Use includes and check in sql usage

This commit is contained in:
Ajay Ramachandran 2023-01-28 12:18:34 -05:00 committed by GitHub
parent 74c0ba37e2
commit d8e0eac61b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,7 +23,7 @@ export async function shadowBanUser(req: Request, res: Response): Promise<Respon
const categories: Category[] = parseCategories(req, config.categoryList as Category[]);
if (adminUserIDInput == undefined || (userID == undefined && hashedIP == undefined || type !== "1" && type !== "2")) {
if (adminUserIDInput == undefined || (userID == undefined && hashedIP == undefined || !["1", "2"].includes(type))) {
//invalid request
return res.sendStatus(400);
}
@ -119,6 +119,8 @@ export async function shadowBanUser(req: Request, res: Response): Promise<Respon
}
async function unHideSubmissions(categories: string[], userID: UserID, type = "1") {
if (!["1", "2"].includes(type)) return;
await db.prepare("run", `UPDATE "sponsorTimes" SET "shadowHidden" = ${type} WHERE "userID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})
AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE
"sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."service" = "lockCategories"."service" AND "sponsorTimes"."category" = "lockCategories"."category")`, [userID]);