import Controller from "./Controller"; import FunkyArray from "funky-array"; import UserService from "../services/UserService"; import HomeViewModel from "../models/home/HomeViewModel"; import PartyService from "../services/PartyService"; import BadgeService from "../services/BadgeService"; import Badge from "../entities/Badge"; import UserBadge from "../entities/UserBadge"; export default class HomeController extends Controller { public async Index_Get_AllowAnonymous() { if (this.session) { const user = await UserService.GetUser(this.session.userId); if (!user) { return this.unauthorised(); } const parties = await PartyService.GetUserParties(this.session.userId); const activeUserParty = await UserService.GetActiveParty(this.session.userId); const unlockedBadges = await UserService.LoadUserBadges(this.session.userId); const unlockedBadgesById = new FunkyArray(); for (const unlockedBadge of unlockedBadges) { unlockedBadgesById.set(unlockedBadge.BadgeId, unlockedBadge); } const badges = await BadgeService.LoadAll(); const badgeById = new FunkyArray(); for (const badge of badges) { badgeById.set(badge.Id, badge); } const homeViewModel: HomeViewModel = { user, parties, activeUserParty, unlockedBadges, unlockedBadgesById, badgeById }; return this.view("home", homeViewModel); } return this.view(); } }