diff --git a/packages/server/server/data/migrations/20200120215211_timeSetting.js b/packages/server/server/data/migrations/20200120215211_timeSetting.js new file mode 100644 index 0000000..b3df335 --- /dev/null +++ b/packages/server/server/data/migrations/20200120215211_timeSetting.js @@ -0,0 +1,15 @@ +const timeTypes = ['untimed','game', 'byoYomi', 'move']; + +exports.up = function(knex) { + return knex.schema.createTable("time_setting", table => { + table.increments('id').primary(); + table.enu('main_time', timeTypes).notNullable(); + table.integer('time_period').notNullable(); // number of periods + table.integer('period_length').notNullable(); // length in seconds + table.enu('overtime', timeTypes).notNullable(); + table.integer('overtime_period').notNullable(); // number of periods + table.integer('overtime_length').notNullable(); // length in seconds + }) +}; + +exports.down = knex => knex.schema.dropTableIfExists("time_setting"); \ No newline at end of file diff --git a/packages/server/server/data/queries/timeSetting.js b/packages/server/server/data/queries/timeSetting.js new file mode 100644 index 0000000..f2c6922 --- /dev/null +++ b/packages/server/server/data/queries/timeSetting.js @@ -0,0 +1,19 @@ +const knex = require('../db') + +const findTimeSetting = async (timeSetting) => { + const timeQuery = { + main_time: timeSetting.mainTime, + time_period: timeSetting.timePeriod, + period_length: timeSetting.periodLength, + overtime: timeSetting.overtime, + overtime_period: timeSetting.overtimePeriod, + overtime_length: timeSetting.overtimeLength + } + return await knex('time_setting') + .where({...timeSetting}) + .select('id'); +} + +module.exports = { + findTimeSetting +} \ No newline at end of file diff --git a/packages/server/server/data/seeds/timeSetting.js b/packages/server/server/data/seeds/timeSetting.js new file mode 100644 index 0000000..d209428 --- /dev/null +++ b/packages/server/server/data/seeds/timeSetting.js @@ -0,0 +1,11 @@ + +exports.seed = function(knex) { + // Deletes ALL existing entries + return knex('time_setting').del() + .then(function () { + // Inserts seed entries + return knex('time_setting').insert([ + {id: 1, main_time: 'untimed', time_period: 1, period_length: 0, overtime: 'untimed', overtime_period: 0, overtime_length: 0}, + ]); + }); +}; \ No newline at end of file