add opponents

This commit is contained in:
2023-08-17 08:25:51 -05:00
parent 469c298753
commit c9eaadf688
4 changed files with 113 additions and 6 deletions

View File

@@ -387,4 +387,53 @@ router.get("/:team_id/events", ensureLoggedIn, function (req, res, next) {
});
});
router.get("/:team_id/opponents", ensureLoggedIn, function (req, res, next) {
authTeamsnap(req.user);
team_id = req.params.team_id;
teamsnap.loadCollections(function (err) {
teamsnap.bulkLoad(team_id, ["team", "opponent"]).then((items) => {
res.set("Content-Type", "text/html");
res.render("opponents", {
team: items.find((i) => i.type == "team" && i.id == team_id),
opponents: items.filter((i) => i.type == "opponent"),
team_id: team_id,
});
});
});
});
router.get(
"/:team_id/opponent/:opponent_id",
ensureLoggedIn,
function (req, res, next) {
authTeamsnap(req.user);
team_id = req.params.team_id;
opponent_id = req.params.opponent_id;
teamsnap.loadCollections(function (err) {
teamsnap.enablePersistence();
teamsnap
.bulkLoad(team_id, ["team", "opponent"])
.then(() => {
teamsnap.loadTeamMedia(team_id);
})
.then(() => {
items = teamsnap.getAllItems();
res.set("Content-Type", "text/html");
res.render("opponent", {
team: items.find((i) => i.type == "team" && i.id == team_id),
opponent: items.find(
(i) => i.type == "opponent" && i.id == opponent_id
),
opponent_logo: items.find(
(i) =>
i.type == "teamMedium" &&
i.description == `team-logo-${opponent_id}.png`
),
team_id: team_id,
});
});
});
}
);
module.exports = router;