diff --git a/packages/play-node-go/server/controllers/api/apiRoom.js b/packages/play-node-go/server/controllers/api/apiRoom.js index 819cacc..20e7028 100644 --- a/packages/play-node-go/server/controllers/api/apiRoom.js +++ b/packages/play-node-go/server/controllers/api/apiRoom.js @@ -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) { diff --git a/packages/play-node-go/server/data/queries/room.js b/packages/play-node-go/server/data/queries/room.js new file mode 100644 index 0000000..0b2e8ab --- /dev/null +++ b/packages/play-node-go/server/data/queries/room.js @@ -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 +} \ No newline at end of file diff --git a/packages/play-node-go/server/test/room/api.room.spec.js b/packages/play-node-go/server/test/room/api.room.spec.js index 048760b..527da88 100644 --- a/packages/play-node-go/server/test/room/api.room.spec.js +++ b/packages/play-node-go/server/test/room/api.room.spec.js @@ -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 => {