28 lines
1011 B
TypeScript
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);
|
|
}
|
|
}
|
|
}
|