mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-29 02:07:55 +08:00
parent
0b24ec2afb
commit
e419187d2c
4 changed files with 64 additions and 1 deletions
|
|
@ -306,6 +306,15 @@ export async function getPersonalBests(
|
|||
return new MonkeyResponse("Personal bests retrieved", data);
|
||||
}
|
||||
|
||||
export async function getStats(
|
||||
req: MonkeyTypes.Request
|
||||
): Promise<MonkeyResponse> {
|
||||
const { uid } = req.ctx.decodedToken;
|
||||
|
||||
const data = (await UserDAL.getStats(uid)) ?? null;
|
||||
return new MonkeyResponse("Personal stats retrieved", data);
|
||||
}
|
||||
|
||||
export async function getFavoriteQuotes(
|
||||
req: MonkeyTypes.Request
|
||||
): Promise<MonkeyResponse> {
|
||||
|
|
|
|||
|
|
@ -307,6 +307,16 @@ router.get(
|
|||
asyncHandler(UserController.getPersonalBests)
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/stats",
|
||||
RateLimit.userGet,
|
||||
authenticateRequest({
|
||||
acceptApeKeys: true,
|
||||
}),
|
||||
apeRateLimit,
|
||||
asyncHandler(UserController.getStats)
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/favoriteQuotes",
|
||||
RateLimit.quoteFavoriteGet,
|
||||
|
|
|
|||
|
|
@ -511,6 +511,18 @@ export async function getPersonalBests(
|
|||
return user.personalBests?.[mode];
|
||||
}
|
||||
|
||||
export async function getStats(
|
||||
uid: string
|
||||
): Promise<{ [key: string]: number | undefined }> {
|
||||
const user = await getUser(uid, "get stats");
|
||||
|
||||
return {
|
||||
startedTests: user.startedTests,
|
||||
completedTests: user.completedTests,
|
||||
timeTyping: user.timeTyping,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getFavoriteQuotes(
|
||||
uid
|
||||
): Promise<MonkeyTypes.User["favoriteQuotes"]> {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
"email": "jack@monkeytype.com"
|
||||
}
|
||||
},
|
||||
"basePath": "/",
|
||||
"basePath": "api.monkeytype.com/",
|
||||
"consumes": ["application/json"],
|
||||
"produces": ["application/json"],
|
||||
"tags": [
|
||||
|
|
@ -54,6 +54,20 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/users/stats": {
|
||||
"get": {
|
||||
"tags": ["users"],
|
||||
"summary": "Gets a user's typing stats data",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Stats"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/leaderboards": {
|
||||
"get": {
|
||||
"tags": ["leaderboards"],
|
||||
|
|
@ -204,6 +218,24 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"Stats": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"startedTests": {
|
||||
"type": "integer",
|
||||
"example": 578
|
||||
},
|
||||
"completedTests": {
|
||||
"type": "integer",
|
||||
"example": 451
|
||||
},
|
||||
"timeTyping": {
|
||||
"type": "number",
|
||||
"format": "double",
|
||||
"example": 3941.6
|
||||
}
|
||||
}
|
||||
},
|
||||
"LeaderboardEntry": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue