Files
ZYZ/web-server/app/controller/game.ts
2020-11-22 22:43:24 +08:00

28 lines
1011 B
TypeScript

import { STATUS } from '@consts/statusCode';
import Game, { GameModel } from '@db/Game';
import { Controller } from 'egg';
export default class GameController extends Controller {
public async getServerList() {
const { ctx } = this;
const { serverType } = ctx.request.body;
const serverList: Array<any> = await GameModel.getServerListByType(serverType);
if (serverList && serverList.length > 0) {
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { serverList });
} else {
ctx.body = ctx.service.utils.resResult(STATUS.SERVER_NOT_FOUND);
}
}
public async newServer() {
const { ctx } = this;
const { serverId, serverType, name, host, port, status } = ctx.request.body;
const gameInfo = await GameModel.newServer(serverId, serverType, name, host, port, status);
if (gameInfo) {
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { gameInfo });
} else {
ctx.body = ctx.service.utils.resResult(STATUS.NEW_SERVER_ERR);
}
}
}