mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-26 09:20:24 -05:00
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { requireUser } from "~/features/auth/core/user.server";
|
|
import * as BadgeRepository from "~/features/badges/BadgeRepository.server";
|
|
import { requirePermission } from "~/modules/permissions/guards.server";
|
|
import { organizationFromParams } from "../tournament-organization-utils.server";
|
|
|
|
export async function loader({ params }: LoaderFunctionArgs) {
|
|
const user = requireUser();
|
|
const organization = await organizationFromParams(params);
|
|
|
|
requirePermission(organization, "EDIT", user);
|
|
|
|
const badgeOptions = async () => {
|
|
const result = await BadgeRepository.findByManagersList(
|
|
organization.members.map((member) => member.id),
|
|
);
|
|
|
|
// handles edge case where the badge is not managed by the org anymore for whatever reason
|
|
// -> let's still keep it still deletable
|
|
for (const badge of organization.badges) {
|
|
if (!result.find((b) => b.id === badge.id)) {
|
|
result.push(badge);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
};
|
|
|
|
return {
|
|
organization,
|
|
badgeOptions: await badgeOptions(),
|
|
};
|
|
}
|