mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-06 21:34:28 -05:00
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { db } from "~/db/sql";
|
|
|
|
export async function findByUserIdWithActivity(userId: number) {
|
|
const rows = await db
|
|
.selectFrom("Friendship")
|
|
.innerJoin("User", (join) =>
|
|
join.on((eb) =>
|
|
eb.or([
|
|
eb.and([
|
|
eb("Friendship.userOneId", "=", userId),
|
|
eb("User.id", "=", eb.ref("Friendship.userTwoId")),
|
|
]),
|
|
eb.and([
|
|
eb("Friendship.userTwoId", "=", userId),
|
|
eb("User.id", "=", eb.ref("Friendship.userOneId")),
|
|
]),
|
|
]),
|
|
),
|
|
)
|
|
.leftJoin("TournamentSub", "TournamentSub.userId", "User.id")
|
|
.leftJoin(
|
|
"CalendarEvent",
|
|
"CalendarEvent.tournamentId",
|
|
"TournamentSub.tournamentId",
|
|
)
|
|
.leftJoin(
|
|
"CalendarEventDate",
|
|
"CalendarEventDate.eventId",
|
|
"CalendarEvent.id",
|
|
)
|
|
.select([
|
|
"User.id",
|
|
"User.username",
|
|
"User.discordId",
|
|
"User.discordAvatar",
|
|
"User.customUrl",
|
|
"CalendarEvent.name as tournamentName",
|
|
"TournamentSub.tournamentId",
|
|
"CalendarEventDate.startTime as tournamentStartTime",
|
|
])
|
|
.where((eb) =>
|
|
eb.or([
|
|
eb("Friendship.userOneId", "=", userId),
|
|
eb("Friendship.userTwoId", "=", userId),
|
|
]),
|
|
)
|
|
.orderBy("Friendship.createdAt", "desc")
|
|
.execute();
|
|
|
|
return rows;
|
|
}
|