mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-23 11:57:50 -05:00
* Initial * CSS lint * Test CI * Add 1v1, 2v2, and 3v3 Tags (#1771) * Initial * CSS lint * Test CI * Rename step --------- Co-authored-by: xi <104683822+ximk@users.noreply.github.com>
45 lines
1.1 KiB
TypeScript
45 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 { isAdmin } from "~/permissions";
|
|
import { parseRequestFormData, validate } from "~/utils/remix";
|
|
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 parseRequestFormData({
|
|
request,
|
|
schema,
|
|
});
|
|
|
|
const posts = await LFGRepository.posts(user);
|
|
const post = posts.find((post) => post.id === data.id);
|
|
validate(post, "Post not found");
|
|
validate(isAdmin(user) || post.author.id === user.id, "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,
|
|
}),
|
|
]);
|