serve all public rooms at rooms index
This commit is contained in:
parent
762c4d93a8
commit
6114c20e2c
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) => {
|
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) {
|
||||||
|
|
|
@ -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 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 => {
|
||||||
|
|
Loading…
Reference in a new issue