base work for badge view on user page

This commit is contained in:
Holly Stubbs 2024-10-08 09:41:47 +01:00
parent d7330dcec3
commit d83eef15c0
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
5 changed files with 40 additions and 2 deletions

View file

@ -13,11 +13,13 @@ export default class HomeController extends Controller {
const parties = await PartyService.GetUserParties(this.session.userId); const parties = await PartyService.GetUserParties(this.session.userId);
const activeUserParty = await UserService.GetActiveParty(this.session.userId); const activeUserParty = await UserService.GetActiveParty(this.session.userId);
const unlockedBadges = await UserService.LoadUserBadges(this.session.userId);
const homeViewModel: HomeViewModel = { const homeViewModel: HomeViewModel = {
user, user,
parties, parties,
activeUserParty activeUserParty,
unlockedBadges
}; };
return this.view("home", homeViewModel); return this.view("home", homeViewModel);

View file

@ -1,9 +1,11 @@
import Party from "../../entities/Party"; import Party from "../../entities/Party";
import User from "../../entities/User"; import User from "../../entities/User";
import UserBadge from "../../entities/UserBadge";
import UserParty from "../../entities/UserParty"; import UserParty from "../../entities/UserParty";
export default interface HomeViewModel { export default interface HomeViewModel {
user: User, user: User,
parties: Array<Party>, parties: Array<Party>,
activeUserParty: UserParty | null activeUserParty: UserParty | null,
unlockedBadges: Array<UserBadge>
} }

View file

@ -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<UserBadge>();
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) { 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 ]); 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) { if (dbUserBadge == null || dbUserBadge.length === 0) {

View file

@ -269,4 +269,13 @@ export default class UserService {
throw e; 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;
}
}
} }

View file

@ -61,4 +61,16 @@
<% } %> <% } %>
</div> </div>
</div> </div>
<div class="row">
<div class="col">
<h3>Badges</h3>
<div class="row mt-4">
<div class="col">
<% for (let i = 0; i < 71; i++) { %>
<img class="mb-3" src="https://eusv.net/Mu6LedXkxrZDUB">
<% } %>
</div>
</div>
</div>
</div>
<%- include("../base/footer") %> <%- include("../base/footer") %>