2020-01-21 07:05:55 +00:00
|
|
|
const knex = require('../db');
|
2020-01-18 23:49:35 +00:00
|
|
|
|
2020-01-22 00:01:35 +00:00
|
|
|
const joinGameSection = [
|
|
|
|
'room.id', 'room.name', 'room.description', 'room.language',
|
|
|
|
'game.komi', 'game.handicap', 'game.board_size',
|
|
|
|
'game.player_black', 'game.player_white',
|
|
|
|
'game.player_black_rank', 'game.player_white_rank'
|
|
|
|
]
|
|
|
|
|
2020-01-18 23:49:35 +00:00
|
|
|
const findPublicRooms = async () => {
|
|
|
|
return await knex('room')
|
|
|
|
.where('private', false)
|
2020-01-21 07:05:55 +00:00
|
|
|
.select(['id', 'name', 'description', 'language']);
|
2020-01-18 23:49:35 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 00:01:35 +00:00
|
|
|
const findRoomById = async (roomId) => {
|
|
|
|
|
|
|
|
return await knex
|
|
|
|
.from('room')
|
|
|
|
.select(joinGameSection)
|
|
|
|
.where('room.id', '=', roomId)
|
|
|
|
.join('game', function() {
|
|
|
|
this.on('game.room', '=', 'room.id')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-01-18 23:49:35 +00:00
|
|
|
module.exports = {
|
2020-01-22 00:01:35 +00:00
|
|
|
findPublicRooms,
|
|
|
|
findRoomById
|
2020-01-18 23:49:35 +00:00
|
|
|
}
|