55 lines
1.3 KiB
TypeScript

import type { IncomingMessage, ServerResponse } from "http";
import { authorizeRequest } from "../../../../../lib/butil";
import { Permissions } from "../../../../../lib/permissions";
import { db } from "../../../../../server";
import type { Graph } from "../../../_types";
export async function get(
req: IncomingMessage & {
params: { graph: string; profile: string; player: string };
},
res: ServerResponse
) {
const [_, exit] = await authorizeRequest(req, res, db, [
Permissions.VIEW_PROFILES
]);
if (exit) return;
const cnf = db.collection("config");
const profile = db.collection("c" + req.params.profile);
if (!(await profile.exists())) {
res.writeHead(404);
res.end(
JSON.stringify({
message: "Profile not found"
})
);
}
let graph: Graph = await cnf.document(req.params.graph);
switch (graph.type) {
case "manual_graph":
let data = await (
await db.query({
query: `FOR profile IN ${profile.name}
LET member = profile.members[@member_uuid]
${graph.data.value}`,
bindVars: {
member_uuid: req.params.player
}
})
).all();
res.writeHead(200);
res.end(JSON.stringify(data));
return;
default:
res.writeHead(404);
res.end(
JSON.stringify({
message: "Not a graph ID"
})
);
return;
}
}