serve all public rooms at rooms index

This commit is contained in:
Sorrel Bri 2020-01-18 15:49:35 -08:00 committed by sorrelbri
parent a6105973f3
commit d81be0b595
3 changed files with 15 additions and 5 deletions

View file

@ -1,11 +1,10 @@
// const roomQueries = require('../../data/queries/room'); const roomQueries = require('../../data/queries/room');
const roomIndex = async (req, res, next) => { const roomIndex = async (req, res, next) => {
try { try {
// TODO eventually add check for user's private rooms // TODO eventually add check for user's private rooms
const publicRooms = await roomQueries.findPublicRooms();
res.status(200).json({rooms: publicRooms})
res.status(200).json({rooms: [{id: 1, name: 'main', description: 'A general place to play Go'}]})
} }
catch (err) { catch (err) {

View 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
}

View file

@ -1,6 +1,6 @@
const apiRoomSpec = (chai, knex, server) => { const apiRoomSpec = (chai, knex, server) => {
const roomEndpoint = '/api/v1/rooms'; 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 => { it('seeded rooms should be present in db', done => {
knex('room').where('id', 1).orWhere('id', 2).select('name').then(roomResults => { knex('room').where('id', 1).orWhere('id', 2).select('name').then(roomResults => {