Skip to content

Commit

Permalink
add /api/greenboxhistory for getting specific greenbox entries
Browse files Browse the repository at this point in the history
  • Loading branch information
soolar committed Nov 24, 2023
1 parent 4b53fe2 commit cefebe2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,41 @@ app
greenboxLastUpdate: latestGreenbox.time,
});
})
.get("/api/greenboxhistory/:playerId/:greenboxNumber", async (req, res) => {
const playerId = Number(req.params.playerId);
const greenboxNumber = Number(req.params.greenboxNumber);

if (Number.isNaN(playerId) || playerId < 1)
return res
.status(StatusCodes.BAD_REQUEST)
.json({ error: "playerId is invalid" });

if (Number.isNaN(greenboxNumber) || greenboxNumber < 1)
return res
.status(StatusCodes.BAD_REQUEST)
.json({ error: "greenboxNumber is invalid" });

const greenboxEntry = await prisma.greenbox.findFirst({
where: { playerId },
orderBy: { id: "asc" },
skip: greenboxNumber - 1,
select: {
player: true,
data: true,
time: true,
},
});

if (!greenboxEntry)
return res.status(StatusCodes.NOT_FOUND).json({
error: `Player has either no greenbox data, or less than ${greenboxNumber} updates`,
});

return res.status(StatusCodes.OK).json({
greenboxString: greenboxEntry.data,
greenboxLastUpdate: greenboxEntry.time,
});
})
.get("/webhooks/subsrolling", async (req, res) => {
const token = req.query.token;

Expand Down

0 comments on commit cefebe2

Please sign in to comment.