mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-24 20:44:52 -05:00
* Migrations * Arrange admin UI * Load staff from DB * Fix TODO * Can add/remove staff * isTournamentAdmin / isTournamentOrganizer * Show chat to streamer * User titles in the chat * chat name color * Unique constraint * TO Staff E2E tests * Casts on stream page * Streamer test * Fix test
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import { getStreams } from "~/modules/twitch";
|
|
import { participantTwitchUsersByTournamentId } from "../queries/participantTwitchUsersByTournamentId.server";
|
|
|
|
export async function streamsByTournamentId({
|
|
tournamentId,
|
|
castTwitchAccounts,
|
|
}: {
|
|
tournamentId: number;
|
|
castTwitchAccounts: string[] | null;
|
|
}) {
|
|
// 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 {
|
|
...stream,
|
|
userId: user.id,
|
|
};
|
|
}
|
|
|
|
if (castTwitchAccounts?.includes(stream.twitchUserName)) {
|
|
return {
|
|
...stream,
|
|
userId: null,
|
|
};
|
|
}
|
|
|
|
return [];
|
|
});
|
|
|
|
return tournamentStreams;
|
|
}
|