t00-multiuser/server/controller/HomeController.ts

28 lines
No EOL
769 B
TypeScript

import { FastifyReply, FastifyRequest } from "fastify";
import Controller from "./Controller";
import UserService from "../services/UserService";
import HomeViewModel from "../models/home/HomeViewModel";
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 UserService.GetUserParties(this.session.userId);
const activeUserParty = await UserService.GetActiveParty(this.session.userId);
const homeViewModel: HomeViewModel = {
user,
parties,
activeUserParty
};
return this.view("home", homeViewModel);
}
return this.view();
}
}