Skip to content

Commit

Permalink
/user: Links to primary and secondary account
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Jun 6, 2024
1 parent 409b3c6 commit 32dbd38
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ router.get('/:user', function (req, res) {
: `https://discord.com/users/${userid.split('_')[1]}`;
const platformIconClass = isSteamUser ? 'fa-brands fa-steam' : 'fa-brands fa-discord';

// Check for associations
let associationType = null;
let associatedProfileUrl = null;
let associatedId = null;

const parentAssociation = db.prepare('SELECT parent_id FROM associations WHERE child_id = ?').get(userid);
const childAssociation = db.prepare('SELECT child_id FROM associations WHERE parent_id = ?').get(userid);

if (parentAssociation) {
const Id = parentAssociation.parent_id;
associationType = 'Primary account';
associatedProfileUrl = `/user/${Id}`;
associatedId = Id;
}
else if (childAssociation) {
const Id = childAssociation.child_id;
associationType = 'Secondary account';
associatedProfileUrl = `/user/${Id}`;
associatedId = Id;
}

const stmtTeam = db.prepare('SELECT * FROM mmr_team WHERE account_id = ?');
const userTeam = stmtTeam.get(userid) || { mmr: 0, sigma: 0, mu: 0, matches_won: 0, matches_lost: 0 };
const rankTeam = ranks.getRank(parseInt(userTeam.mmr));
Expand Down Expand Up @@ -97,7 +118,10 @@ router.get('/:user', function (req, res) {
platformIconClass: platformIconClass,
teamData: userTeam,
ffaData: userFFA,
matches: matches
matches: matches,
associationType: associationType,
associatedProfileUrl: associatedProfileUrl,
associatedId: associatedId
};

res.render('user', render_data);
Expand Down
10 changes: 9 additions & 1 deletion views/user.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
<tr>
<td style="min-width: 150px;">External profile</td>
<td style="min-width: 300px;">
<a href="<%= profileUrl %>" target="_blank"><i class="<%= platformIconClass %>"></i> <%= platformName %><span class="external-link-icon" aria-hidden="true"></span></a>
<a href="<%= profileUrl %>" target="_blank"><i class="<%= platformIconClass %>"></i> <%= platformName %><span class="external-link-icon" aria-hidden="true"></span></a>
</tr>
<% if (associationType && associatedProfileUrl && associatedId) { %>
<tr>
<td style="min-width: 150px;"><%= associationType %></td>
<td style="min-width: 300px;">
<a href="<%= associatedProfileUrl %>"><%= associatedId %></a>
</td>
</tr>
<% } %>
<tr>
<td style="min-width: 150px;">Name</td>
<td style="min-width: 300px;"><%= nickname %></td>
Expand Down

0 comments on commit 32dbd38

Please sign in to comment.