node-go/packages/play-node-go/server/controllers/api/apiRoom.js

41 lines
1 KiB
JavaScript
Raw Normal View History

2020-01-18 23:49:35 +00:00
const roomQueries = require('../../data/queries/room');
const messageQueries = require('../../data/queries/message');
const gameQueries = require('../../data/queries/game');
const socket = require('../../socket');
2020-01-18 23:42:45 +00:00
const getAll = async (req, res, next) => {
2020-01-18 23:42:45 +00:00
try {
2020-01-24 00:04:40 +00:00
const publicRooms = await roomQueries.findPublicRooms();
res.status(200).json({rooms: [...publicRooms]})
2020-01-18 23:42:45 +00:00
}
catch (err) {
res.status(500).json(err);
}
}
const show = async (req, res, next) => {
try {
const roomId = req.params.id;
if (!roomId) throw('missing room parameter')
// TODO eventually add check for user's private rooms
// socket.roomSocket(roomId);
const currentRoom = await roomQueries.findRoomById(roomId);
const messages = await messageQueries.findMessageByRoom(roomId);
const roomGames = await gameQueries.findGameByRoom(roomId);
const body = {currentRoom, messages, roomGames};
res.status(200).json(body);
}
catch (err) {
console.log(err)
res.status(500).json(err);
}
}
2020-01-18 23:42:45 +00:00
module.exports = {
getAll,
show
2020-01-18 23:42:45 +00:00
}