Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add appeal submit status endpoint
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent b6c051f commit ffe7010
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions functions/api/appeals/submit.ts
@@ -1,7 +1,28 @@
import { jsonError } from "../../common.js";
import { jsonError, jsonResponse } from "../../common.js";

export async function onRequestGet(context: RequestContext) {
const { current_user: currentUser } = context.data;

if (
!currentUser.email ||
(await context.env.DATA.get("appeal_disabled")) ||
(await context.env.D1.prepare(
"SELECT id FROM appeals WHERE open = 1 AND user = ?;",
)
.bind(currentUser.id)
.first()) ||
(await context.env.DATA.get(`blockedappeal_${currentUser.id}`))
)
return jsonResponse('{"can_appeal":false}');

return jsonResponse('{"can_appeal":true}');
}

export async function onRequestPost(context: RequestContext) {
const { learned, whyBanned, whyUnban } = context.data.body;
if (await context.env.DATA.get("appeal_disabled"))
return jsonError("Appeals are disabled", 403);

const { learned, senderTokenId, whyBanned, whyUnban } = context.data.body;

if (
typeof learned !== "string" ||
Expand Down Expand Up @@ -58,6 +79,7 @@ export async function onRequestPost(context: RequestContext) {
JSON.stringify({
ban_reason: whyBanned,
created_at: Date.now(),
fcm_token: typeof senderTokenId === "string" ? senderTokenId : undefined,
learned,
id: appealId,
reason_for_unban: whyUnban,
Expand Down

0 comments on commit ffe7010

Please sign in to comment.