claude/discord-qualifying-points-t55s3x #121
2 changed files with 14 additions and 10 deletions
|
|
@ -448,7 +448,7 @@ export async function assignCs2EliminationQP(
|
|||
const existingQPBySPId = new Map<string, number>(
|
||||
existingRows
|
||||
.filter((r) => r.qualifyingPointsAwarded !== null)
|
||||
.map((r) => [r.seasonParticipantId, parseFloat(r.qualifyingPointsAwarded!)])
|
||||
.map((r) => [r.seasonParticipantId, parseFloat(r.qualifyingPointsAwarded as string)])
|
||||
);
|
||||
|
||||
await writeEventResultsQP(scoringEventId, sportsSeasonId, resultsByParticipant, db);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { database } from "~/database/context";
|
||||
import type { database } from "~/database/context";
|
||||
import * as schema from "~/database/schema";
|
||||
import { eq, inArray } from "drizzle-orm";
|
||||
import { findDiscordIdsByUserIds } from "~/models/account";
|
||||
|
|
@ -40,7 +40,7 @@ export async function notifyQualifyingPointsUpdate(
|
|||
eventResultRows
|
||||
.filter((r) => r.qualifyingPointsAwarded !== null)
|
||||
.filter((r) => !participantIdFilter || participantIdFilter.has(r.seasonParticipantId))
|
||||
.map((r) => [r.seasonParticipantId, parseFloat(r.qualifyingPointsAwarded!)])
|
||||
.map((r) => [r.seasonParticipantId, parseFloat(r.qualifyingPointsAwarded as string)])
|
||||
);
|
||||
|
||||
if (qpEarnedById.size === 0) return;
|
||||
|
|
@ -69,8 +69,12 @@ export async function notifyQualifyingPointsUpdate(
|
|||
});
|
||||
const picksBySeasonId = new Map<string, (typeof allPicks)[number][]>();
|
||||
for (const pick of allPicks) {
|
||||
if (!picksBySeasonId.has(pick.seasonId)) picksBySeasonId.set(pick.seasonId, []);
|
||||
picksBySeasonId.get(pick.seasonId)!.push(pick);
|
||||
const bucket = picksBySeasonId.get(pick.seasonId);
|
||||
if (bucket) {
|
||||
bucket.push(pick);
|
||||
} else {
|
||||
picksBySeasonId.set(pick.seasonId, [pick]);
|
||||
}
|
||||
}
|
||||
|
||||
// Batch-fetch participant display names once (same participants across all leagues)
|
||||
|
|
@ -99,10 +103,11 @@ export async function notifyQualifyingPointsUpdate(
|
|||
|
||||
for (const { seasonId } of seasonSports) {
|
||||
const season = seasonMap.get(seasonId);
|
||||
const webhookUrl = season?.league?.discordWebhookUrl;
|
||||
if (!webhookUrl) continue;
|
||||
const league = season?.league;
|
||||
const webhookUrl = league?.discordWebhookUrl;
|
||||
if (!webhookUrl || !season || !league) continue;
|
||||
|
||||
const seasonName = `${season!.league!.name} ${season!.year}`;
|
||||
const seasonName = `${league.name} ${season.year}`;
|
||||
|
||||
const picks = picksBySeasonId.get(seasonId) ?? [];
|
||||
const teamByParticipantId = new Map<
|
||||
|
|
@ -123,8 +128,7 @@ export async function notifyQualifyingPointsUpdate(
|
|||
if (relevantParticipantIds.length === 0) continue;
|
||||
|
||||
const entries: QPEventEntry[] = relevantParticipantIds.map((participantId) => {
|
||||
const teamInfo = teamByParticipantId.get(participantId)!;
|
||||
const ownerId = teamInfo.ownerId;
|
||||
const ownerId = teamByParticipantId.get(participantId)?.ownerId ?? null;
|
||||
return {
|
||||
participantName: participantNameById.get(participantId) ?? participantId,
|
||||
qpEarned: qpEarnedById.get(participantId) ?? 0,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue