Verify old submissions when adding dearrow feature

This commit is contained in:
Ajay 2023-09-06 10:53:14 -04:00
parent 8361f602c7
commit d08c423c6a
2 changed files with 7 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import { isUserVIP } from "../utils/isUserVIP";
import { Feature, HashedUserID, UserID } from "../types/user.model";
import { Logger } from "../utils/logger";
import { QueryCacher } from "../utils/queryCacher";
import { getVerificationValue, verifyOldSubmissions } from "./postBranding";
interface AddFeatureRequest extends Request {
body: {
@ -58,6 +59,10 @@ export async function addFeature(req: AddFeatureRequest, res: Response): Promise
await db.prepare("run", 'INSERT INTO "userFeatures" ("userID", "feature", "issuerUserID", "timeSubmitted") VALUES(?, ?, ?, ?)'
, [userID, feature, adminUserID, Date.now()]);
}
if (feature === Feature.DeArrowTitleSubmitter) {
await verifyOldSubmissions(userID, await getVerificationValue(userID, false));
}
} else {
await db.prepare("run", 'DELETE FROM "userFeatures" WHERE "userID" = ? AND "feature" = ?', [userID, feature]);
}

View file

@ -173,7 +173,7 @@ async function updateVoteTotals(type: BrandingType, existingVote: ExistingVote,
}
}
async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean): Promise<number> {
export async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean): Promise<number> {
const voteSum = await db.prepare("get", `SELECT SUM("maxVotes") as "voteSum" FROM (SELECT MAX("votes") as "maxVotes" from "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID" WHERE "titles"."userID" = ? GROUP BY "titles"."videoID") t`, [hashedUserID]);
const sbSubmissions = () => db.prepare("get", `SELECT COUNT(*) as count FROM "sponsorTimes" WHERE "userID" = ? AND "votes" > 0 LIMIT 3`, [hashedUserID]);
@ -184,7 +184,7 @@ async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean):
}
}
async function verifyOldSubmissions(hashedUserID: HashedUserID, verification: number): Promise<void> {
export async function verifyOldSubmissions(hashedUserID: HashedUserID, verification: number): Promise<void> {
if (verification >= 0) {
const unverifiedSubmissions = await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service" FROM "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID" WHERE "titles"."userID" = ? AND "titleVotes"."verification" < ? GROUP BY "videoID", "hashedVideoID", "service"`, [hashedUserID, verification]);