( req: MonkeyRequest<GetProfileQuery, undefined, GetProfilePathParams>, )
| 911 | } |
| 912 | |
| 913 | export async function getProfile( |
| 914 | req: MonkeyRequest<GetProfileQuery, undefined, GetProfilePathParams>, |
| 915 | ): Promise<GetProfileResponse> { |
| 916 | const { uidOrName } = req.params; |
| 917 | |
| 918 | const user = req.query.isUid |
| 919 | ? await UserDAL.getUser(uidOrName, "get user profile") |
| 920 | : await UserDAL.getUserByName(uidOrName, "get user profile"); |
| 921 | |
| 922 | const { |
| 923 | name, |
| 924 | banned, |
| 925 | inventory, |
| 926 | profileDetails, |
| 927 | personalBests, |
| 928 | completedTests, |
| 929 | startedTests, |
| 930 | timeTyping, |
| 931 | addedAt, |
| 932 | discordId, |
| 933 | discordAvatar, |
| 934 | xp, |
| 935 | streak, |
| 936 | lbOptOut, |
| 937 | } = user; |
| 938 | |
| 939 | const extractValid = ( |
| 940 | src: Record<string, PersonalBest[]>, |
| 941 | validKeys: string[], |
| 942 | ): Record<string, PersonalBest[]> => { |
| 943 | return validKeys.reduce((obj, key) => { |
| 944 | if (src?.[key] !== undefined) { |
| 945 | obj[key] = src[key]; |
| 946 | } |
| 947 | return obj; |
| 948 | }, {}); |
| 949 | }; |
| 950 | |
| 951 | const validTimePbs = extractValid(personalBests.time, [ |
| 952 | "15", |
| 953 | "30", |
| 954 | "60", |
| 955 | "120", |
| 956 | ]); |
| 957 | const validWordsPbs = extractValid(personalBests.words, [ |
| 958 | "10", |
| 959 | "25", |
| 960 | "50", |
| 961 | "100", |
| 962 | ]); |
| 963 | |
| 964 | const typingStats = { |
| 965 | completedTests, |
| 966 | startedTests, |
| 967 | timeTyping, |
| 968 | }; |
| 969 | |
| 970 | const relevantPersonalBests = { |
nothing calls this directly
no test coverage detected