sendou.ink/app/features/tournament/core/streams.server.ts
Kalle 7342dd1667
Tournament team page (#1380)
* 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
2023-05-28 15:25:46 +03:00

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;
}