Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create action endpoint
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 4d76aaf commit 5b65bd1
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions functions/api/reports/[id]/action.ts
@@ -0,0 +1,47 @@
import { insertLogs } from "../../../gcloud.js";
import { getBanList, setBanList } from "../../../roblox-open-cloud.js";

export async function onRequestPost(context: RequestContext) {
const actionMap = context.data.body;
const newActions: { [k: string]: { BanType: number } } = {};
const logMap: { [k: string]: number } = {};

for (const [user, action] of Object.entries(actionMap)) {
if (
isNaN(parseInt(user)) ||
typeof action !== "number" ||
action < 0 ||
action > 2
)
return new Response('{"error":"Invalid action map"}', {
headers: {
"content-type": "application/json",
},
});

if (action === 0) continue;

Object.defineProperty(newActions, user, {
value: {
BanType: action,
},
});

Object.defineProperty(logMap, user, {
value: action,
});
}

await insertLogs(logMap, context.params.id as string, context);

const banList = (await getBanList(context)) as {
[k: string]: { BanType: number };
};

Object.assign(banList, newActions);
await setBanList(context, banList);

return new Response(null, {
status: 204,
});
}

0 comments on commit 5b65bd1

Please sign in to comment.