mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import type { ActionFunction } from "react-router";
|
|
import { requireUser } from "~/features/auth/core/user.server";
|
|
import {
|
|
clearTournamentDataCache,
|
|
tournamentFromDB,
|
|
} from "~/features/tournament-bracket/core/Tournament.server";
|
|
import {
|
|
errorToastIfFalsy,
|
|
parseParams,
|
|
parseRequestPayload,
|
|
} from "~/utils/remix.server";
|
|
import { idObject } from "~/utils/zod";
|
|
import { deleteSub } from "../queries/deleteSub.server";
|
|
import { deleteSubSchema } from "../tournament-subs-schemas.server";
|
|
|
|
export const action: ActionFunction = async ({ request, params }) => {
|
|
const user = requireUser();
|
|
const { id: tournamentId } = parseParams({
|
|
params,
|
|
schema: idObject,
|
|
});
|
|
const tournament = await tournamentFromDB({ tournamentId, user });
|
|
const data = await parseRequestPayload({
|
|
request,
|
|
schema: deleteSubSchema,
|
|
});
|
|
|
|
errorToastIfFalsy(
|
|
user.id === data.userId || tournament.isOrganizer(user),
|
|
"You can only delete your own sub post",
|
|
);
|
|
|
|
deleteSub({
|
|
tournamentId,
|
|
userId: data.userId,
|
|
});
|
|
|
|
clearTournamentDataCache(tournamentId);
|
|
|
|
return null;
|
|
};
|