From b25ac9952715ea7ae8b261b27e55722604664318 Mon Sep 17 00:00:00 2001 From: Bruce Berrios <58147810+Bruception@users.noreply.github.com> Date: Tue, 7 Jun 2022 17:10:58 -0400 Subject: [PATCH] Add leaderboard avatars and badges (#3069) bruception * Add leaderboard avatars and badges * Add discord id * badges -> badgeIds --- backend/src/api/controllers/leaderboard.ts | 2 +- backend/src/api/controllers/result.ts | 3 +++ backend/src/dal/leaderboards.ts | 2 ++ backend/src/documentation/public-swagger.json | 17 ++++++++++++++++- backend/src/types/types.d.ts | 1 + backend/src/utils/daily-leaderboards.ts | 3 +++ frontend/src/ts/types/types.d.ts | 4 +++- 7 files changed, 29 insertions(+), 3 deletions(-) diff --git a/backend/src/api/controllers/leaderboard.ts b/backend/src/api/controllers/leaderboard.ts index 893f493a8..32ebde9fb 100644 --- a/backend/src/api/controllers/leaderboard.ts +++ b/backend/src/api/controllers/leaderboard.ts @@ -40,7 +40,7 @@ export async function getLeaderboard( const normalizedLeaderboard = _.map(leaderboard, (entry) => { return uid && entry.uid === uid ? entry - : _.omit(entry, ["discordId", "uid", "difficulty", "language"]); + : _.omit(entry, ["_id", "difficulty", "language"]); }); return new MonkeyResponse("Leaderboard retrieved", normalizedLeaderboard); diff --git a/backend/src/api/controllers/result.ts b/backend/src/api/controllers/result.ts index f1d083b3e..c6b99ac15 100644 --- a/backend/src/api/controllers/result.ts +++ b/backend/src/api/controllers/result.ts @@ -335,6 +335,9 @@ export async function addResult( consistency: result.consistency, timestamp: result.timestamp, uid, + discordAvatar: user.discordAvatar, + discordId: user.discordId, + badgeIds: user.badgeIds, }, dailyLeaderboardsConfig ); diff --git a/backend/src/dal/leaderboards.ts b/backend/src/dal/leaderboards.ts index f88432abe..95eddf6a3 100644 --- a/backend/src/dal/leaderboards.ts +++ b/backend/src/dal/leaderboards.ts @@ -86,6 +86,8 @@ export async function update( [str + ".uid"]: "$uid", [str + ".name"]: "$name", [str + ".discordId"]: "$discordId", + [str + ".discordAvatar"]: "$discordAvatar", + [str + ".badgeIds"]: "$badgeIds", }, }, { diff --git a/backend/src/documentation/public-swagger.json b/backend/src/documentation/public-swagger.json index cb7e017a3..625f40170 100644 --- a/backend/src/documentation/public-swagger.json +++ b/backend/src/documentation/public-swagger.json @@ -257,7 +257,7 @@ "LeaderboardEntry": { "type": "object", "properties": { - "_id": { + "uid": { "type": "string", "example": "6226b17aebc27a4a8d1ce04b" }, @@ -300,6 +300,21 @@ "timestamp": { "type": "integer", "example": 1644438189583 + }, + "discordId": { + "type": "string", + "example": "974761412044437307" + }, + "discordAvatar": { + "type": "string", + "example": "6226b17aebc27a4a8d1ce04b" + }, + "badgeIds": { + "type": "array", + "items": { + "type": "integer", + "example": 1 + } } } }, diff --git a/backend/src/types/types.d.ts b/backend/src/types/types.d.ts index 47a38d08e..8ca10c872 100644 --- a/backend/src/types/types.d.ts +++ b/backend/src/types/types.d.ts @@ -89,6 +89,7 @@ declare namespace MonkeyTypes { favoriteQuotes?: Record; needsToChangeName?: boolean; discordAvatar?: string; + badgeIds?: number[]; } type UserQuoteRatings = Record>; diff --git a/backend/src/utils/daily-leaderboards.ts b/backend/src/utils/daily-leaderboards.ts index 1e16dc23c..77aec019e 100644 --- a/backend/src/utils/daily-leaderboards.ts +++ b/backend/src/utils/daily-leaderboards.ts @@ -13,6 +13,9 @@ interface DailyLeaderboardEntry { timestamp: number; rank?: number; count?: number; + discordAvatar?: string; + discordId?: string; + badgeIds?: number[]; } const dailyLeaderboardNamespace = "monkeytypes:dailyleaderboard"; diff --git a/frontend/src/ts/types/types.d.ts b/frontend/src/ts/types/types.d.ts index 8eeca3dee..35cc7bde3 100644 --- a/frontend/src/ts/types/types.d.ts +++ b/frontend/src/ts/types/types.d.ts @@ -421,7 +421,7 @@ declare namespace MonkeyTypes { } interface LeaderboardEntry { - _id: string; + uid: string; difficulty: string; timestamp: number; language: string; @@ -433,6 +433,8 @@ declare namespace MonkeyTypes { uid?: string; name: string; discordId?: string; + discordAvatar?: string; + badgeIds?: number[]; rank: number; count?: number; hidden?: boolean;