✨ feat(gvgBattle): 填充接口,通过部分激战期用例测试

This commit is contained in:
liangtongchuan
2023-02-17 10:58:06 +08:00
committed by luying
parent 31a286d82e
commit 92191cbcca
5 changed files with 95 additions and 22 deletions
@@ -4,9 +4,10 @@ import { GVGTeamModel } from '../../../db/GVGTeam';
import { GVGUserDataModel } from '../../../db/GVGUserData';
import { GVGCityModel } from '../../../db/GVGCity';
import { Application, BackendSession, ChannelService, HandlerService } from "pinus";
import { STATUS } from "../../../consts";
import { DEBUG_MAGIC_WORD, STATUS } from "../../../consts";
import { LineupHero } from "../../../domain/roleField/hero";
import { resResult, genCode } from "../../../pubUtils/util";
import { GVGConfigModel } from '../../../db/GVGConfig';
export default function (app: Application) {
new HandlerService(app, {});
@@ -26,6 +27,7 @@ export class GVGBattleHandler {
// spine: 形象
// lineup: 阵容
async saveTeam(msg: { index: number, head: number, frame: number, spine: number, lineup: [ LineupHero ] }, session: BackendSession) {
const { index, head, frame, spine, lineup } = msg;
return resResult(STATUS.SUCCESS, { teams: [ 'teamCode' ] });
}
@@ -41,12 +43,20 @@ export class GVGBattleHandler {
async enterCity(msg: { cityId: number }, session: BackendSession) {
const { cityId } = msg;
let valid = false;
if (!valid) {
let city = await GVGCityModel.findOne({ cityId }).lean();
if (!city) {
return resResult(STATUS.GVG_CITY_NOT_FOUND);
}
const { teamCnt, userCnt } = city;
// 检测是否满员
if (userCnt >= 200) {
return resResult(STATUS.GVG_BATTLE_CITY_FULL);
}
const city = await GVGCityModel.findOne({ cityId }).lean();
// ! 更新城池人数和队伍数,更新用户城池信息
return resResult(STATUS.SUCCESS, { city });
}
@@ -175,4 +185,27 @@ export class GVGBattleHandler {
]);
return resResult(STATUS.SUCCESS, { teams });
}
// debug 接口,创建城市
async createCity(msg: { cityId: number, magicWord: string }, session: BackendSession) {
const { cityId, magicWord } = msg;
if (magicWord !== DEBUG_MAGIC_WORD) {
return resResult(STATUS.INTERNAL_ERR);
}
// 检查城市是否存在
let city = await GVGCityModel.getCityByCityId(cityId);
if (city) {
return resResult(STATUS.SUCCESS, { city });
}
// 创建城市
const config = await GVGConfigModel.findConfig();
if (!config || !config.configId) {
return resResult(STATUS.INTERNAL_ERR);
}
const { configId } = config;
city = await GVGCityModel.createCity(cityId, configId);
return resResult(STATUS.SUCCESS, { city });
}
}