Skip to content

Commit

Permalink
add reset api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescorpian committed Mar 4, 2025
1 parent 4a8838d commit 5a75bf7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,38 @@ router.get("/wind-history/:stationId", async (ctx) => {
ctx.response.body = stream;
});

router.delete("/reset-wind-history", authMiddleware, async (ctx) => {
const entries = await kv.list<TableDataItem>({
prefix: ["windHistoryData"],
});
const stations = await kv.list<StationStats>({
prefix: ["station"],
});
const transaction = kv.atomic();
for await (const entry of entries) {
transaction.delete(entry.key);
}
for await (const station of stations) {
transaction.set(["station", station.value.id], {
...station.value,
totalEntries: 0,
months: {},
});
}

const result = await transaction.commit();
if (result.ok) {
ctx.response.body = { msg: "Deleted all wind history data" };
ctx.response.status = 200;
} else {
ctx.response.body = {
msg: "Failed to delete wind history data",
result,
};
ctx.response.status = 500;
}
});

const app = new Application();
app.use(oakCors({ origin: Deno.env.get("ORIGIN") || "*" }));
app.use(router.routes());
Expand Down

0 comments on commit 5a75bf7

Please sign in to comment.