feat: add /announcements/from-game endpoint
This commit is contained in:
@@ -41,6 +41,10 @@ const AnnouncementIdInput = z.object({
|
||||
announcementId: z.coerce.number().positive(),
|
||||
});
|
||||
|
||||
const GetFromGame = z.object({
|
||||
gameName: z.string().nonempty(),
|
||||
});
|
||||
|
||||
app.get("/api/announcements", async (_, res) => {
|
||||
const announcements = await db
|
||||
.selectFrom("announcements")
|
||||
@@ -50,6 +54,18 @@ app.get("/api/announcements", async (_, res) => {
|
||||
res.json(announcements);
|
||||
});
|
||||
|
||||
app.get("/api/announcements/from-game", async (req, res) => {
|
||||
const fromGameData = GetFromGame.parse(req.query);
|
||||
console.log(`Request from game ${fromGameData.gameName}`);
|
||||
const announcements = await db
|
||||
.selectFrom("announcements")
|
||||
.select(["id", "title", "text", "publication_date", "image"])
|
||||
.orderBy("announcements.publication_date", "desc")
|
||||
.limit(3)
|
||||
.execute();
|
||||
res.json(announcements);
|
||||
});
|
||||
|
||||
app.get("/api/announcements/:announcementId", async (req, res) => {
|
||||
const { announcementId } = AnnouncementIdInput.parse(req.params);
|
||||
const announcement = await db
|
||||
|
||||
Reference in New Issue
Block a user