Create user history endpoint
This commit is contained in:
parent
fe58ffd3fd
commit
62a6c3a1f1
53
functions/api/game-bans/[user]/history.ts
Normal file
53
functions/api/game-bans/[user]/history.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { queryLogs } from "../../../gcloud.js";
|
||||||
|
|
||||||
|
export async function onRequestGet(context: RequestContext) {
|
||||||
|
const robloxUserReq = await fetch(
|
||||||
|
"https://users.roblox.com/v1/usernames/users",
|
||||||
|
{
|
||||||
|
body: JSON.stringify({
|
||||||
|
excludeBannedUsers: false,
|
||||||
|
usernames: [context.params.user as string],
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!robloxUserReq.ok) {
|
||||||
|
console.log(await robloxUserReq.json());
|
||||||
|
return new Response('{"error":"Failed to resolve username"}', {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
status: 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,
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify(
|
||||||
|
(await queryLogs(users[0].id, context)).sort((a, b) =>
|
||||||
|
a.entity.properties.executed_at.integerValue >
|
||||||
|
b.entity.properties.executed_at.integerValue
|
||||||
|
? 1
|
||||||
|
: -1
|
||||||
|
)
|
||||||
|
),
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user