panorama/apps/codetrack/index.ts

28 lines
790 B
TypeScript
Raw Normal View History

2024-07-10 05:12:17 +00:00
import type { Context } from "koa";
2024-07-10 08:11:19 +00:00
import type {} from "@koa/bodyparser";
2024-07-10 05:12:17 +00:00
export async function createHeartbeats(ctx: Context) {
const results = [];
for (const heartbeat of ctx.request.body) {
console.log("heartbeat", heartbeat);
2024-07-10 08:11:19 +00:00
const time = new Date(heartbeat.time * 1000.0);
2024-07-10 05:12:17 +00:00
const resp = await fetch("http://localhost:3000/node", {
method: "PUT",
2024-07-10 08:11:19 +00:00
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
attributes: [
["panorama::time/start", time.toISOString()],
["panorama/codetrack::project", heartbeat.project],
],
}),
2024-07-10 05:12:17 +00:00
});
const data = await resp.json();
results.push({
id: data.id,
});
}
ctx.status = 400;
2024-07-10 08:11:19 +00:00
// console.log("results", results);
2024-07-10 05:12:17 +00:00
ctx.body = {};
}