mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-28 14:18:04 -05:00
Plus Voting to 60% criteria + leaderboard access (#1537)
* Update PlusVotingResult * Logic * Replace plus tiers * Testing initial * Test progress * Working one test * Tests * Schema different file * Dynamic test * Fix test util
This commit is contained in:
@@ -2,6 +2,7 @@ import { db, sql } from "~/db/sql";
|
||||
import { syncXPBadges } from "../badges";
|
||||
import type { Tables } from "~/db/tables";
|
||||
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
const removeOldLikesStm = sql.prepare(/*sql*/ `
|
||||
delete from
|
||||
@@ -48,23 +49,25 @@ export function migrate(args: { newUserId: number; oldUserId: number }) {
|
||||
});
|
||||
}
|
||||
|
||||
export function refreshPlusTiers() {
|
||||
export function replacePlusTiers(
|
||||
plusTiers: Array<{ userId: number; tier: number }>,
|
||||
) {
|
||||
invariant(plusTiers.length > 0, "plusTiers must not be empty");
|
||||
|
||||
return db.transaction().execute(async (trx) => {
|
||||
await trx.deleteFrom("PlusTier").execute();
|
||||
|
||||
await trx
|
||||
.insertInto("PlusTier")
|
||||
.columns(["userId", "tier"])
|
||||
.expression((eb) =>
|
||||
eb
|
||||
.selectFrom("FreshPlusTier")
|
||||
.select(["FreshPlusTier.userId", "FreshPlusTier.tier"])
|
||||
.where("FreshPlusTier.tier", "is not", null),
|
||||
)
|
||||
.execute();
|
||||
await trx.insertInto("PlusTier").values(plusTiers).execute();
|
||||
});
|
||||
}
|
||||
|
||||
export function allPlusTiersFromLatestVoting() {
|
||||
return db
|
||||
.selectFrom("FreshPlusTier")
|
||||
.select(["FreshPlusTier.userId", "FreshPlusTier.tier"])
|
||||
.where("FreshPlusTier.tier", "is not", null)
|
||||
.execute() as Promise<{ userId: number; tier: number }[]>;
|
||||
}
|
||||
|
||||
export function makeVideoAdderByUserId(userId: number) {
|
||||
return db
|
||||
.updateTable("User")
|
||||
|
||||
Reference in New Issue
Block a user