mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-07-27 13:58:59 -05:00
Add id to badge
This commit is contained in:
parent
9963963db2
commit
bca8fd6da8
|
|
@ -2,11 +2,11 @@ import { sql } from "../sql";
|
|||
import type { Badge, User } from "../types";
|
||||
|
||||
const countsByUserIdStm = sql.prepare(`
|
||||
select "Badge"."code", "Badge"."displayName", count("BadgeOwner"."code") as count
|
||||
select "Badge"."code", "Badge"."displayName", count("BadgeOwner"."badgeId") as count
|
||||
from "BadgeOwner"
|
||||
join "Badge" on "Badge"."code" = "BadgeOwner"."code"
|
||||
join "Badge" on "Badge"."id" = "BadgeOwner"."badgeId"
|
||||
where "BadgeOwner"."userId" = $userId
|
||||
group by "BadgeOwner"."code", "BadgeOwner"."userId"
|
||||
group by "BadgeOwner"."badgeId", "BadgeOwner"."userId"
|
||||
`);
|
||||
|
||||
export type CountsByUserId = Array<
|
||||
|
|
|
|||
|
|
@ -202,22 +202,22 @@ function thisMonthsSuggestions() {
|
|||
function badgesToAdmin() {
|
||||
const availableBadgeCodes = shuffle(
|
||||
sql
|
||||
.prepare(`select "code" from "Badge"`)
|
||||
.prepare(`select "id" from "Badge"`)
|
||||
.all()
|
||||
.map((b) => b.code)
|
||||
).slice(0, 8) as string[];
|
||||
.map((b) => b.id)
|
||||
).slice(0, 8) as number[];
|
||||
|
||||
const badgesWithDuplicates = availableBadgeCodes.flatMap((code) =>
|
||||
const badgesWithDuplicates = availableBadgeCodes.flatMap((id) =>
|
||||
new Array(faker.helpers.arrayElement([1, 1, 1, 2, 3, 4]))
|
||||
.fill(null)
|
||||
.map(() => code)
|
||||
.map(() => id)
|
||||
);
|
||||
|
||||
for (const code of badgesWithDuplicates) {
|
||||
for (const id of badgesWithDuplicates) {
|
||||
sql
|
||||
.prepare(
|
||||
`insert into "BadgeOwner" ("code", "userId") values ($code, $userId)`
|
||||
`insert into "BadgeOwner" ("badgeId", "userId") values ($id, $userId)`
|
||||
)
|
||||
.run({ code, userId: 1 });
|
||||
.run({ id, userId: 1 });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,16 +53,17 @@ export interface PlusTier {
|
|||
}
|
||||
|
||||
export interface Badge {
|
||||
id: number;
|
||||
code: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export interface BadgeOwner {
|
||||
code: string;
|
||||
badgeId: number;
|
||||
userId: number;
|
||||
}
|
||||
|
||||
export interface BadgeManager {
|
||||
code: string;
|
||||
badgeId: number;
|
||||
userId: number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ module.exports.up = function (db) {
|
|||
db.prepare(
|
||||
`
|
||||
create table "Badge" (
|
||||
"code" text not null primary key,
|
||||
"id" integer primary key,
|
||||
"code" text not null,
|
||||
"displayName" text not null
|
||||
) strict
|
||||
`
|
||||
|
|
@ -17,7 +18,7 @@ module.exports.up = function (db) {
|
|||
db.prepare(
|
||||
`
|
||||
create table "BadgeOwner" (
|
||||
"code" text not null,
|
||||
"badgeId" integer not null,
|
||||
"userId" integer not null
|
||||
) strict
|
||||
`
|
||||
|
|
@ -26,9 +27,9 @@ module.exports.up = function (db) {
|
|||
db.prepare(
|
||||
`
|
||||
create table "BadgeManager" (
|
||||
"code" text not null,
|
||||
"badgeId" integer not null,
|
||||
"userId" integer not null,
|
||||
unique("code", "userId") on conflict rollback
|
||||
unique("badgeId", "userId") on conflict rollback
|
||||
) strict
|
||||
`
|
||||
).run();
|
||||
|
|
@ -163,7 +164,7 @@ function initialBadgesForDb() {
|
|||
displayName: "LUTI Season 12 (Div 8)",
|
||||
},
|
||||
{
|
||||
code: "lutitan2",
|
||||
code: "lutitan",
|
||||
displayName: "LUTI Season 12 (Div 9)",
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 121 KiB |
Loading…
Reference in New Issue
Block a user