mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-02 08:07:40 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { db } from "~/db/sql";
|
||||
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
||||
import { commonUserSelect, jsonObjectFrom } from "~/utils/kysely.server";
|
||||
import type { Unwrapped } from "~/utils/types";
|
||||
|
||||
export type ActiveMatchPlayersItem = Unwrapped<
|
||||
typeof findAllActiveMatchPlayers
|
||||
>;
|
||||
export function findAllActiveMatchPlayers() {
|
||||
const oneHourAgo = new Date(Date.now() - 1000 * 60 * 60);
|
||||
|
||||
return db
|
||||
.selectFrom("Group")
|
||||
.innerJoin("GroupMatch", (join) =>
|
||||
join.on((eb) =>
|
||||
eb.or([
|
||||
eb("GroupMatch.alphaGroupId", "=", eb.ref("Group.id")),
|
||||
eb("GroupMatch.bravoGroupId", "=", eb.ref("Group.id")),
|
||||
]),
|
||||
),
|
||||
)
|
||||
.innerJoin("GroupMember", "GroupMember.groupId", "Group.id")
|
||||
.innerJoin("LiveStream", "LiveStream.userId", "GroupMember.userId")
|
||||
.select(({ eb }) => [
|
||||
"GroupMatch.id as groupMatchId",
|
||||
"GroupMatch.createdAt as groupMatchCreatedAt",
|
||||
"LiveStream.twitch as streamTwitch",
|
||||
"LiveStream.viewerCount as streamViewerCount",
|
||||
"LiveStream.thumbnailUrl as streamThumbnailUrl",
|
||||
jsonObjectFrom(
|
||||
eb
|
||||
.selectFrom("User")
|
||||
.select((eb) => [...commonUserSelect(eb), "User.twitch"])
|
||||
.whereRef("GroupMember.userId", "=", "User.id"),
|
||||
).as("user"),
|
||||
])
|
||||
.where("Group.status", "=", "ACTIVE")
|
||||
.where("GroupMatch.createdAt", ">", dateToDatabaseTimestamp(oneHourAgo))
|
||||
.execute();
|
||||
}
|
||||
Reference in New Issue
Block a user