mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-15 23:41:53 -05:00
* WIP * Query * Backend for team page done * UI function made * UI work * Tweaks * Fix showing players from own team * Optimize performance * Inactive players styling * Stage popover
32 lines
796 B
TypeScript
32 lines
796 B
TypeScript
import { getStreams } from "~/modules/twitch";
|
|
import { participantTwitchUsersByTournamentId } from "../queries/participantTwitchUsersByTournamentId.server";
|
|
|
|
export async function streamsByTournamentId(tournamentId: number) {
|
|
// prevent error logs in development
|
|
if (
|
|
process.env.NODE_ENV === "development" &&
|
|
!process.env["TWITCH_CLIENT_ID"]
|
|
) {
|
|
return [];
|
|
}
|
|
const twitchUsersOfTournament =
|
|
participantTwitchUsersByTournamentId(tournamentId);
|
|
|
|
const streams = await getStreams();
|
|
|
|
const tournamentStreams = streams.flatMap((stream) => {
|
|
const user = twitchUsersOfTournament.find(
|
|
(u) => u.twitch === stream.twitchUserName
|
|
);
|
|
|
|
if (!user) return [];
|
|
|
|
return {
|
|
...stream,
|
|
userId: user.id,
|
|
};
|
|
});
|
|
|
|
return tournamentStreams;
|
|
}
|