增加更新游戏伦次的方法

This commit is contained in:
zhl 2021-04-30 09:45:25 +08:00
parent 6d0f821f04
commit acff67c4ba
3 changed files with 35 additions and 7 deletions

View File

@ -1,6 +0,0 @@
import BaseController from '../../common/base.controller'
import { role, router } from '../../decorators/router'
class ServerController extends BaseController {
}

View File

@ -1,4 +1,10 @@
import { beginGame, endGame, sendQuestion, updateScore } from './WsSvr'
import {
beginGame,
endGame,
sendQuestion,
updateRound,
updateScore
} from './WsSvr'
import { Puzzle } from '../models/content/Puzzle'
import { Schedule } from '../clock/Schedule'
import { BaseConst } from '../constants/BaseConst'
@ -58,6 +64,7 @@ export async function sendOneQuestion(history: any) {
let record = await Puzzle.findById(qid)
let qdata: any = transformRecord([record])[0]
qdata.no = history.current
await updateRound(roomId, history.current)
await sendQuestion(roomId, qdata)
history.current ++
await history.save()

View File

@ -121,6 +121,12 @@ export async function sendQuestion(roomId: string, data: any) {
return broadcast(roomId, 'question', data)
}
/**
*
* @param {string} roomId
* @param data
* @return {Promise<AxiosResponse<any>>}
*/
export async function updateScore(roomId: string, data: any) {
console.log(`updateScore: ${roomId}, ${JSON.stringify(data)}`)
const url = `${apiBase}/room/call`
@ -135,3 +141,24 @@ export async function updateScore(roomId: string, data: any) {
return res.data
})
}
/**
*
* @param {string} roomId
* @param {number} round
* @return {Promise<AxiosResponse<any>>}
*/
export async function updateRound(roomId: string, round: number) {
console.log(`updateRound: ${roomId}, ${round}`)
const url = `${apiBase}/room/call`
const args = [round]
const params = {
roomId,
method: 'updateRound',
args: JSON.stringify(args)
}
return axios.post(url, params)
.then(res => {
return res.data
})
}