增加用户统计接口

This commit is contained in:
zhl 2021-05-20 12:42:20 +08:00
parent 0fb0c7b35c
commit 80df32f693
2 changed files with 33 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import BaseController from '../../common/base.controller'
import { role, router } from '../../decorators/router'
import { GameUser } from '../../models/GameUser'
import { ZError } from '../../common/ZError'
import { getRandom } from '../../utils/number.util'
class GameUserController extends BaseController {
// TODO:: 增加返回未使用的券
@ -19,4 +20,26 @@ class GameUserController extends BaseController {
return {token}
}
@role('anon')
@router('post /api/:accountid/stats')
async userStatic(req: any) {
const data: any = {
map: [
{id: 0, name: '知识面', score: getRandom(20), max: 20},
{id: 1, name: '知识深度', score: getRandom(20), max: 20},
{id: 2, name: '反应能力', score: getRandom(20), max: 20},
{id: 3, name: '毅力', score: getRandom(20), max: 20},
{id: 4, name: '其他', score: getRandom(20), max: 20},
],
rightCount: 100,
errorCount: 100,
singleCount: 20,
singleWin: 15,
singleLose: 5,
activityCount: 20,
examCount: 21
}
return data
}
}

10
src/utils/number.util.ts Normal file
View File

@ -0,0 +1,10 @@
/**
*
* @param {number} max
* @param {number} min
* @return {number}
*/
export function getRandom(max: number, min?: number): number {
min = min || 0;
return Math.floor(Math.random()*(max-min)+min);
}