sendou.ink/app/features/lfg/actions/lfg.server.ts
Kalle d2551d2706
Some checks failed
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
Global roles refactor (#2212)
* Initial

* isMod etc.

* canPerformAdminActions

* isAdmin

* isSupporter

* admin override

* Lohi

* Badge manage with new permissions style

* Refactor badge loading logic

* Move funcs

* Delete permissions.ts

* DRY
2025-04-21 23:51:30 +03:00

47 lines
1.1 KiB
TypeScript

import type { ActionFunctionArgs } from "@remix-run/node";
import { z } from "zod";
import { requireUser } from "~/features/auth/core/user.server";
import { errorToastIfFalsy, parseRequestPayload } from "~/utils/remix.server";
import { _action, id } from "~/utils/zod";
import * as LFGRepository from "../LFGRepository.server";
export const action = async ({ request }: ActionFunctionArgs) => {
const user = await requireUser(request);
const data = await parseRequestPayload({
request,
schema,
});
const posts = await LFGRepository.posts(user);
const post = posts.find((post) => post.id === data.id);
errorToastIfFalsy(post, "Post not found");
errorToastIfFalsy(
post.author.id === user.id || user.roles.includes("ADMIN"),
"Not your own post",
);
switch (data._action) {
case "DELETE_POST": {
await LFGRepository.deletePost(data.id);
break;
}
case "BUMP_POST": {
await LFGRepository.bumpPost(data.id);
break;
}
}
return null;
};
const schema = z.union([
z.object({
_action: _action("DELETE_POST"),
id,
}),
z.object({
_action: _action("BUMP_POST"),
id,
}),
]);