mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { getUser } from "~/features/auth/core/user.server";
|
|
import { SendouQ } from "~/features/sendouq/core/SendouQ.server";
|
|
import * as PrivateUserNoteRepository from "~/features/sendouq/PrivateUserNoteRepository.server";
|
|
import { reportedWeaponsToArrayOfArrays } from "~/features/sendouq-match/core/reported-weapons.server";
|
|
import { reportedWeaponsByMatchId } from "~/features/sendouq-match/queries/reportedWeaponsByMatchId.server";
|
|
import * as SQMatchRepository from "~/features/sendouq-match/SQMatchRepository.server";
|
|
import { notFoundIfFalsy, parseParams } from "~/utils/remix.server";
|
|
import { qMatchPageParamsSchema } from "../q-match-schemas";
|
|
|
|
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|
const user = getUser();
|
|
const matchId = parseParams({
|
|
params,
|
|
schema: qMatchPageParamsSchema,
|
|
}).id;
|
|
const matchUnmapped = notFoundIfFalsy(
|
|
await SQMatchRepository.findById(matchId),
|
|
);
|
|
|
|
const matchUsers = [
|
|
...matchUnmapped.groupAlpha.members,
|
|
...matchUnmapped.groupBravo.members,
|
|
].map((m) => m.id);
|
|
const privateNotes = user
|
|
? await PrivateUserNoteRepository.byAuthorUserId(user.id, matchUsers)
|
|
: undefined;
|
|
|
|
const match = SendouQ.mapMatch(matchUnmapped, user, privateNotes);
|
|
|
|
const rawReportedWeapons = match.reportedAt
|
|
? reportedWeaponsByMatchId(matchId)
|
|
: null;
|
|
|
|
return {
|
|
match,
|
|
reportedWeapons: match.reportedAt
|
|
? reportedWeaponsToArrayOfArrays({
|
|
groupAlpha: match.groupAlpha,
|
|
groupBravo: match.groupBravo,
|
|
mapList: match.mapList,
|
|
reportedWeapons: rawReportedWeapons,
|
|
})
|
|
: null,
|
|
rawReportedWeapons,
|
|
};
|
|
};
|