From d0f26d9a6c4613bdc1dc92c4720396d3c13e34ba Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Mon, 20 Jan 2020 23:05:55 -0800 Subject: [PATCH] add game table with seed and migration --- server/data/migrations/20200120224032_game.js | 37 +++++++++++++++++++ server/data/queries/game.js | 23 ++++++++++++ server/data/queries/room.js | 4 +- server/test/spec.js | 1 - 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 server/data/migrations/20200120224032_game.js create mode 100644 server/data/queries/game.js diff --git a/server/data/migrations/20200120224032_game.js b/server/data/migrations/20200120224032_game.js new file mode 100644 index 0000000..2f293da --- /dev/null +++ b/server/data/migrations/20200120224032_game.js @@ -0,0 +1,37 @@ +const winType = [ + 'B+R', 'B+', 'B+T', + 'W+R', 'W+', 'W+T', + '0', 'Void', '?' +] + +exports.up = function(knex) { + return knex.schema.createTable("game", table => { + table.increments('id').primary(); + table.datetime('date'); + table.float('komi').default(6.5); + table.integer('handicap').default(0); + table.integer('board_size').default(19); + + table.string('application'); + table.string('application_version'); + + table.string('player_black'); + table.string('player_white'); + table.string('event'); + table.string('name'); + table.string('description'); + table.integer('round'); + + table.enu('win_type', winType); + table.float('score'); + table.integer('black_captures'); + table.integer('white_captures'); + + table.integer('user_black').references('id').inTable('user'); + table.integer('user_white').references('id').inTable('user'); + table.integer('room').references('id').inTable('room'); + table.integer('time_setting').references('id').inTable('time_setting'); + }) +}; + +exports.down = knex => knex.schema.dropTableIfExists("game"); \ No newline at end of file diff --git a/server/data/queries/game.js b/server/data/queries/game.js new file mode 100644 index 0000000..83edf27 --- /dev/null +++ b/server/data/queries/game.js @@ -0,0 +1,23 @@ +const knex = require('../db'); + +const findGameById = async (gameId) => { + return await knex('game') + .where({'id': gameId}) + .select('*'); +} + +const findGameByRoom = async (roomId) => { + return await knex('game') + .where({'id': roomId}) + .select('*'); +} + +const insertGame = async (game) => { + +} + +module.exports = { + findGameById, + findGameByRoom, + insertGame +} \ No newline at end of file diff --git a/server/data/queries/room.js b/server/data/queries/room.js index 0b2e8ab..b08edf9 100644 --- a/server/data/queries/room.js +++ b/server/data/queries/room.js @@ -1,9 +1,9 @@ -const knex = require('../db') +const knex = require('../db'); const findPublicRooms = async () => { return await knex('room') .where('private', false) - .select(['id', 'name', 'description', 'language']) + .select(['id', 'name', 'description', 'language']); } module.exports = { diff --git a/server/test/spec.js b/server/test/spec.js index d5f35f0..43fdfc8 100644 --- a/server/test/spec.js +++ b/server/test/spec.js @@ -15,7 +15,6 @@ const apiRoomSpec = require('./room/api.room.spec'); chai.use(chaiHttp); // ! to run tests from other testing modules -// import someTest from './endpoint/someTest'; const setupDb = () => { beforeEach(done => {