base work for badge view on user page
This commit is contained in:
parent
d7330dcec3
commit
d83eef15c0
5 changed files with 40 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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<Party>,
|
||||
activeUserParty: UserParty | null
|
||||
activeUserParty: UserParty | null,
|
||||
unlockedBadges: Array<UserBadge>
|
||||
}
|
|
@ -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) {
|
||||
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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -61,4 +61,16 @@
|
|||
<% } %>
|
||||
</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") %>
|
Loading…
Reference in a new issue