From 3f8d898f436692389c2ed25a274f4d4557d47b5d 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 --- .../data/migrations/20200120224032_game.js | 37 +++++++++++++++++++ packages/server/server/data/queries/game.js | 23 ++++++++++++ packages/server/server/data/queries/room.js | 4 +- packages/server/server/test/spec.js | 1 - 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 packages/server/server/data/migrations/20200120224032_game.js create mode 100644 packages/server/server/data/queries/game.js diff --git a/packages/server/server/data/migrations/20200120224032_game.js b/packages/server/server/data/migrations/20200120224032_game.js new file mode 100644 index 0000000..2f293da --- /dev/null +++ b/packages/server/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/packages/server/server/data/queries/game.js b/packages/server/server/data/queries/game.js new file mode 100644 index 0000000..83edf27 --- /dev/null +++ b/packages/server/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/packages/server/server/data/queries/room.js b/packages/server/server/data/queries/room.js index 0b2e8ab..b08edf9 100644 --- a/packages/server/server/data/queries/room.js +++ b/packages/server/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/packages/server/server/test/spec.js b/packages/server/server/test/spec.js index d5f35f0..43fdfc8 100644 --- a/packages/server/server/test/spec.js +++ b/packages/server/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 => {