mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-20 10:04:57 -05:00
Clear tournament cache when avatar is approved
This commit is contained in:
14
app/features/img-upload/ImageRepository.server.ts
Normal file
14
app/features/img-upload/ImageRepository.server.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { db } from "~/db/sql";
|
||||
|
||||
export function findById(id: number) {
|
||||
return db
|
||||
.selectFrom("UnvalidatedUserSubmittedImage")
|
||||
.leftJoin(
|
||||
"CalendarEvent",
|
||||
"CalendarEvent.avatarImgId",
|
||||
"UnvalidatedUserSubmittedImage.id",
|
||||
)
|
||||
.select(["CalendarEvent.tournamentId"])
|
||||
.where("UnvalidatedUserSubmittedImage.id", "=", id)
|
||||
.executeTakeFirst();
|
||||
}
|
||||
@@ -3,9 +3,16 @@ import { Form, useLoaderData } from "@remix-run/react";
|
||||
import { Main } from "~/components/Main";
|
||||
import { SubmitButton } from "~/components/SubmitButton";
|
||||
import { requireUserId } from "~/features/auth/core/user.server";
|
||||
import { clearTournamentDataCache } from "~/features/tournament-bracket/core/Tournament.server";
|
||||
import { isMod } from "~/permissions";
|
||||
import { notFoundIfFalsy, parseRequestFormData, validate } from "~/utils/remix";
|
||||
import {
|
||||
badRequestIfFalsy,
|
||||
notFoundIfFalsy,
|
||||
parseRequestFormData,
|
||||
validate,
|
||||
} from "~/utils/remix";
|
||||
import { userSubmittedImage } from "~/utils/urls";
|
||||
import * as ImageRepository from "../ImageRepository.server";
|
||||
import { countAllUnvalidatedImg } from "../queries/countAllUnvalidatedImg.server";
|
||||
import { oneUnvalidatedImage } from "../queries/oneUnvalidatedImage";
|
||||
import { validateImage } from "../queries/validateImage";
|
||||
@@ -20,8 +27,14 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
|
||||
validate(isMod(user), "Only admins can validate images");
|
||||
|
||||
const image = badRequestIfFalsy(await ImageRepository.findById(data.imageId));
|
||||
|
||||
validateImage(data.imageId);
|
||||
|
||||
if (image.tournamentId) {
|
||||
clearTournamentDataCache(image.tournamentId);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user