mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-27 01:37:19 -05:00
* Initial * CSS lint * Test CI * Add 1v1, 2v2, and 3v3 Tags (#1771) * Initial * CSS lint * Test CI * Rename step --------- Co-authored-by: xi <104683822+ximk@users.noreply.github.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { jsonObjectFrom } from "kysely/helpers/sqlite";
|
|
import { db } from "~/db/sql";
|
|
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
|
import { COMMON_USER_FIELDS } from "~/utils/kysely.server";
|
|
import type { Unwrapped } from "~/utils/types";
|
|
|
|
export type ActiveMatchPlayersItem = Unwrapped<typeof activeMatchPlayers>;
|
|
export function activeMatchPlayers() {
|
|
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")
|
|
.select(({ eb }) => [
|
|
"GroupMatch.id as groupMatchId",
|
|
"GroupMatch.createdAt as groupMatchCreatedAt",
|
|
jsonObjectFrom(
|
|
eb
|
|
.selectFrom("User")
|
|
.select([...COMMON_USER_FIELDS, "User.twitch"])
|
|
.whereRef("GroupMember.userId", "=", "User.id"),
|
|
).as("user"),
|
|
])
|
|
.where("Group.status", "=", "ACTIVE")
|
|
.where("GroupMatch.createdAt", ">", dateToDatabaseTimestamp(oneHourAgo))
|
|
.execute();
|
|
}
|