serve all public rooms at rooms index
This commit is contained in:
parent
a6105973f3
commit
d81be0b595
3 changed files with 15 additions and 5 deletions
|
@ -1,11 +1,10 @@
|
|||
// const roomQueries = require('../../data/queries/room');
|
||||
const roomQueries = require('../../data/queries/room');
|
||||
|
||||
const roomIndex = async (req, res, next) => {
|
||||
try {
|
||||
// TODO eventually add check for user's private rooms
|
||||
|
||||
|
||||
res.status(200).json({rooms: [{id: 1, name: 'main', description: 'A general place to play Go'}]})
|
||||
const publicRooms = await roomQueries.findPublicRooms();
|
||||
res.status(200).json({rooms: publicRooms})
|
||||
}
|
||||
|
||||
catch (err) {
|
||||
|
|
11
packages/play-node-go/server/data/queries/room.js
Normal file
11
packages/play-node-go/server/data/queries/room.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const knex = require('../db')
|
||||
|
||||
const findPublicRooms = async () => {
|
||||
return await knex('room')
|
||||
.where('private', false)
|
||||
.select(['id', 'name', 'description', 'language'])
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
findPublicRooms
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
const apiRoomSpec = (chai, knex, server) => {
|
||||
const roomEndpoint = '/api/v1/rooms';
|
||||
const publicRooms = {rooms: [{id: 1, name: 'main', description: 'A general place to play Go'}]};
|
||||
const publicRooms = {rooms: [{id: 1, name: 'main', description: 'A general place to play Go', language: 'EN'}]};
|
||||
|
||||
it('seeded rooms should be present in db', done => {
|
||||
knex('room').where('id', 1).orWhere('id', 2).select('name').then(roomResults => {
|
||||
|
|
Loading…
Reference in a new issue