diff --git a/app.js b/app.js index c46ee9f..f29b1fb 100644 --- a/app.js +++ b/app.js @@ -121,6 +121,33 @@ app.get("/api/building/:id", async (req, res) => { } }); +app.get("/api/buildings", async (req, res) => { + const userId = req.session.user.id; + + try { + const [rows] = await db.query( + ` + SELECT + b.id, + b.name, + b.description, + b.history, + ub.level, + ub.points + FROM buildings b + LEFT JOIN user_buildings ub + ON ub.building_id = b.id AND ub.user_id = ? + `, + [userId], + ); + + res.json(rows); + } catch (err) { + console.error(err); + res.status(500).json({ error: "DB Fehler" }); + } +}); + /* ======================== Body Parser ======================== */ diff --git a/public/js/building.js b/public/js/building.js new file mode 100644 index 0000000..df3982a --- /dev/null +++ b/public/js/building.js @@ -0,0 +1,17 @@ +fetch("/api/buildings") + .then((res) => res.json()) + .then((buildings) => { + buildings.forEach((building) => { + const element = document.querySelector( + `.building[data-id="${building.id}"]`, + ); + + if (!element) return; + + const title = element.querySelector("title"); + + if (title) { + title.textContent = building.name; + } + }); + }); diff --git a/views/launcher.ejs b/views/launcher.ejs index 5abc2b0..43b6109 100644 --- a/views/launcher.ejs +++ b/views/launcher.ejs @@ -41,8 +41,8 @@ class="map-overlay" > - - Pforte Links + + - - Burg + +