adjust endGame query to modify record with win information
This commit is contained in:
parent
5eca128110
commit
cbf9d461ba
3 changed files with 101 additions and 52 deletions
|
@ -1,49 +1,81 @@
|
||||||
const winType = [
|
const winType = ["B+R", "B+", "B+T", "W+R", "W+", "W+T", "0", "Void", "?"];
|
||||||
'B+R', 'B+', 'B+T',
|
|
||||||
'W+R', 'W+', 'W+T',
|
|
||||||
'0', 'Void', '?'
|
|
||||||
]
|
|
||||||
|
|
||||||
const rankArray = [
|
const rankArray = [
|
||||||
'D9', 'D8', 'D7', 'D6', 'D5', 'D4', 'D3', 'D2', 'D1',
|
"D9",
|
||||||
'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'K10',
|
"D8",
|
||||||
'K11', 'K12', 'K13', 'K14', 'K15', 'K16', 'K17', 'K18', 'K19', 'K20',
|
"D7",
|
||||||
'K21', 'K22', 'K23', 'K24', 'K25', 'K26', 'K27', 'K28', 'K29', 'K30', 'UR'
|
"D6",
|
||||||
]
|
"D5",
|
||||||
|
"D4",
|
||||||
|
"D3",
|
||||||
|
"D2",
|
||||||
|
"D1",
|
||||||
|
"K1",
|
||||||
|
"K2",
|
||||||
|
"K3",
|
||||||
|
"K4",
|
||||||
|
"K5",
|
||||||
|
"K6",
|
||||||
|
"K7",
|
||||||
|
"K8",
|
||||||
|
"K9",
|
||||||
|
"K10",
|
||||||
|
"K11",
|
||||||
|
"K12",
|
||||||
|
"K13",
|
||||||
|
"K14",
|
||||||
|
"K15",
|
||||||
|
"K16",
|
||||||
|
"K17",
|
||||||
|
"K18",
|
||||||
|
"K19",
|
||||||
|
"K20",
|
||||||
|
"K21",
|
||||||
|
"K22",
|
||||||
|
"K23",
|
||||||
|
"K24",
|
||||||
|
"K25",
|
||||||
|
"K26",
|
||||||
|
"K27",
|
||||||
|
"K28",
|
||||||
|
"K29",
|
||||||
|
"K30",
|
||||||
|
"UR",
|
||||||
|
];
|
||||||
|
|
||||||
exports.up = function (knex) {
|
exports.up = function (knex) {
|
||||||
return knex.schema.createTable("game", table => {
|
return knex.schema.createTable("game", (table) => {
|
||||||
table.increments('id').primary();
|
table.increments("id").primary();
|
||||||
table.datetime('date');
|
table.datetime("date");
|
||||||
table.float('komi').default(6.5);
|
table.float("komi").default(6.5);
|
||||||
table.integer('handicap').default(0);
|
table.integer("handicap").default(0);
|
||||||
table.integer('board_size').default(19);
|
table.integer("board_size").default(19);
|
||||||
table.boolean('open').default(true);
|
table.boolean("open").default(true);
|
||||||
|
|
||||||
table.string('application');
|
table.string("application");
|
||||||
table.string('application_version');
|
table.string("application_version");
|
||||||
table.timestamps(true, true);
|
table.timestamps(true, true);
|
||||||
|
|
||||||
table.string('player_black');
|
table.string("player_black");
|
||||||
table.string('player_white');
|
table.string("player_white");
|
||||||
table.enu('player_black_rank', rankArray).default('UR');
|
table.enu("player_black_rank", rankArray).default("UR");
|
||||||
table.enu('player_white_rank', rankArray).default('UR');
|
table.enu("player_white_rank", rankArray).default("UR");
|
||||||
|
|
||||||
table.string('event');
|
table.string("event");
|
||||||
table.string('name');
|
table.string("name");
|
||||||
table.string('description');
|
table.string("description");
|
||||||
table.integer('round');
|
table.integer("round");
|
||||||
|
|
||||||
table.enu('win_type', winType);
|
table.enu("win_type", winType);
|
||||||
table.float('score');
|
table.float("score");
|
||||||
table.integer('captures_black');
|
table.integer("captures_black");
|
||||||
table.integer('captures_white');
|
table.integer("captures_white");
|
||||||
|
|
||||||
table.integer('user_black').references('id').inTable('user');
|
table.integer("user_black").references("id").inTable("user");
|
||||||
table.integer('user_white').references('id').inTable('user');
|
table.integer("user_white").references("id").inTable("user");
|
||||||
table.integer('room').references('id').inTable('room');
|
table.integer("room").references("id").inTable("room");
|
||||||
table.integer('time_setting').references('id').inTable('time_setting');
|
table.integer("time_setting").references("id").inTable("time_setting");
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.down = knex => knex.schema.dropTableIfExists("game");
|
exports.down = (knex) => knex.schema.dropTableIfExists("game");
|
||||||
|
|
|
@ -70,17 +70,23 @@ const findGameByRoom = async (roomId) => {
|
||||||
|
|
||||||
const insertGame = async (game) => {};
|
const insertGame = async (game) => {};
|
||||||
|
|
||||||
const endGame = async ({ id }) => {
|
const endGame = async ({ id, winType, score, bCaptures, wCaptures }) => {
|
||||||
const game = await knex(game).where({ id: id }).update(
|
try {
|
||||||
{
|
const game = await knex
|
||||||
|
.from("game")
|
||||||
|
.returning(gameDetailSelect)
|
||||||
|
.where({ id: id })
|
||||||
|
.update({
|
||||||
win_type: winType,
|
win_type: winType,
|
||||||
score: score,
|
score: score,
|
||||||
captures_black: capturesBlack,
|
captures_black: bCaptures,
|
||||||
captures_white: capturesWhite,
|
captures_white: wCaptures,
|
||||||
}
|
open: false,
|
||||||
// ["id"]
|
});
|
||||||
);
|
|
||||||
return game;
|
return game;
|
||||||
|
} catch (e) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -73,6 +73,7 @@ const GameService = ({ moveQueries, gameQueries }) => {
|
||||||
},
|
},
|
||||||
|
|
||||||
resign: ({ id, player }) => {
|
resign: ({ id, player }) => {
|
||||||
|
// add resign gamesQueries
|
||||||
return gamesInProgress[id].submitResign(player).getMeta();
|
return gamesInProgress[id].submitResign(player).getMeta();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -108,9 +109,19 @@ const GameService = ({ moveQueries, gameQueries }) => {
|
||||||
|
|
||||||
async endGame({ id }) {
|
async endGame({ id }) {
|
||||||
gamesInProgress[id] = gamesInProgress[id].endGame();
|
gamesInProgress[id] = gamesInProgress[id].endGame();
|
||||||
|
const { winner, score, playerState } = gamesInProgress[id];
|
||||||
|
const { bCaptures, wCaptures } = playerState;
|
||||||
|
const winType = winner > 0 ? "B+" : "W+";
|
||||||
try {
|
try {
|
||||||
if (gameQueries) {
|
if (gameQueries) {
|
||||||
// TODO add end game query
|
const result = await gameQueries.endGame({
|
||||||
|
id,
|
||||||
|
winType,
|
||||||
|
score,
|
||||||
|
bCaptures,
|
||||||
|
wCaptures,
|
||||||
|
});
|
||||||
|
console.log(result);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|
Loading…
Reference in a new issue