From 99fa9904910eb9636551663504526c92e9e4a7b0 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:54:45 +0200 Subject: [PATCH] Handle deleting org badges where no longer manager of --- .../loaders/org.$slug.edit.server.ts | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/features/tournament-organization/loaders/org.$slug.edit.server.ts b/app/features/tournament-organization/loaders/org.$slug.edit.server.ts index ca5c73ebf..1491c06ef 100644 --- a/app/features/tournament-organization/loaders/org.$slug.edit.server.ts +++ b/app/features/tournament-organization/loaders/org.$slug.edit.server.ts @@ -11,10 +11,24 @@ export async function loader({ params, request }: LoaderFunctionArgs) { unauthorizedIfFalsy(canEditTournamentOrganization({ organization, 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 BadgeRepository.findByManagersList( - organization.members.map((member) => member.id), - ), + badgeOptions: await badgeOptions(), }; }