Greatly reduce repeated code

This commit is contained in:
2023-10-19 16:50:48 -04:00
parent 47e639be43
commit dd2d9f2672
34 changed files with 196 additions and 481 deletions

View File

@ -1,3 +1,4 @@
import { jsonError, jsonResponse } from "../../../common.js";
import { queryLogs } from "../../../gcloud.js";
export async function onRequestGet(context: RequestContext) {
@ -17,26 +18,15 @@ export async function onRequestGet(context: RequestContext) {
if (!robloxUserReq.ok) {
console.log(await robloxUserReq.json());
return new Response('{"error":"Failed to resolve username"}', {
headers: {
"content-type": "application/json",
},
status: 500,
});
return jsonError("Failed to resolve username", 500);
}
const { data: users }: { data: { [k: string]: any }[] } =
await robloxUserReq.json();
if (!users.length)
return new Response('{"error":"No user found with that name"}', {
headers: {
"content-type": "application/json",
},
status: 400,
});
if (!users.length) return jsonError("No user found with that name", 400);
return new Response(
return jsonResponse(
JSON.stringify(
(await queryLogs(users[0].id, context)).sort((a, b) =>
a.entity.properties.executed_at.integerValue >
@ -45,10 +35,5 @@ export async function onRequestGet(context: RequestContext) {
: -1,
),
),
{
headers: {
"content-type": "application/json",
},
},
);
}