diff --git a/server/controller/HomeController.ts b/server/controller/HomeController.ts index c7c2d99..dff13e5 100644 --- a/server/controller/HomeController.ts +++ b/server/controller/HomeController.ts @@ -13,11 +13,13 @@ export default class HomeController extends Controller { 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 homeViewModel: HomeViewModel = { user, parties, - activeUserParty + activeUserParty, + unlockedBadges }; return this.view("home", homeViewModel); diff --git a/server/models/home/HomeViewModel.ts b/server/models/home/HomeViewModel.ts index 965baf2..5e6671e 100644 --- a/server/models/home/HomeViewModel.ts +++ b/server/models/home/HomeViewModel.ts @@ -1,9 +1,11 @@ import Party from "../../entities/Party"; import User from "../../entities/User"; +import UserBadge from "../../entities/UserBadge"; import UserParty from "../../entities/UserParty"; export default interface HomeViewModel { user: User, parties: Array, - activeUserParty: UserParty | null + activeUserParty: UserParty | null, + unlockedBadges: Array } \ No newline at end of file diff --git a/server/repos/UserBadgeRepo.ts b/server/repos/UserBadgeRepo.ts index 32ffa59..e4b336d 100644 --- a/server/repos/UserBadgeRepo.ts +++ b/server/repos/UserBadgeRepo.ts @@ -14,6 +14,19 @@ export default abstract class UserBadgeRepo { } } + public static async selectByUserId(userId:number) { + const dbUserBadge = await Database.Instance.query("SELECT * FROM UserBadge WHERE UserId = ? AND IsDeleted = 0 LIMIT 1", [ userId ]); + const userBadges = new Array(); + + for (const row of dbUserBadge) { + const userBadge = new UserBadge(); + populateUserBadgeFromDB(userBadge, row); + userBadges.push(userBadge); + } + + return userBadges; + } + public static async selectByUserIdBadgeId(userId:number, badgeId:number) { const dbUserBadge = await Database.Instance.query("SELECT * FROM UserBadge WHERE UserId = ? AND BadgeId = ? AND IsDeleted = 0 LIMIT 1", [ userId, badgeId ]); if (dbUserBadge == null || dbUserBadge.length === 0) { diff --git a/server/services/UserService.ts b/server/services/UserService.ts index 9131da4..a44828e 100644 --- a/server/services/UserService.ts +++ b/server/services/UserService.ts @@ -269,4 +269,13 @@ export default class UserService { throw e; } } + + public static async LoadUserBadges(currentUserId:number) { + try { + return await UserBadgeRepo.selectByUserId(currentUserId); + } catch (e) { + Console.printError(`MultiProbe server service error:\n${e}`); + throw e; + } + } } \ No newline at end of file diff --git a/server/views/home/home.ejs b/server/views/home/home.ejs index aa44cef..4138830 100644 --- a/server/views/home/home.ejs +++ b/server/views/home/home.ejs @@ -61,4 +61,16 @@ <% } %> +
+
+

Badges

+
+
+ <% for (let i = 0; i < 71; i++) { %> + + <% } %> +
+
+
+
<%- include("../base/footer") %> \ No newline at end of file