2020-01-18 23:49:35 +00:00
|
|
|
const roomQueries = require('../../data/queries/room');
|
2020-01-22 01:02:54 +00:00
|
|
|
const messageQueries = require('../../data/queries/message');
|
2020-01-23 22:46:49 +00:00
|
|
|
const gameQueries = require('../../data/queries/game');
|
2020-01-26 00:50:18 +00:00
|
|
|
const socket = require('../../socket');
|
2020-01-18 23:42:45 +00:00
|
|
|
|
2020-01-22 00:01:35 +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();
|
|
|
|
|
2020-01-23 22:46:49 +00:00
|
|
|
res.status(200).json({rooms: [...publicRooms]})
|
2020-01-18 23:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 01:18:42 +00:00
|
|
|
catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
res.status(500).json(e);
|
2020-01-18 23:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 00:01:35 +00:00
|
|
|
const show = async (req, res, next) => {
|
|
|
|
try {
|
|
|
|
const roomId = req.params.id;
|
2020-01-24 05:41:25 +00:00
|
|
|
if (!roomId) throw('missing room parameter')
|
|
|
|
|
2020-01-23 22:46:49 +00:00
|
|
|
// TODO eventually add check for user's private rooms
|
|
|
|
|
|
|
|
const currentRoom = await roomQueries.findRoomById(roomId);
|
2020-01-22 01:02:54 +00:00
|
|
|
const messages = await messageQueries.findMessageByRoom(roomId);
|
2020-01-23 22:46:49 +00:00
|
|
|
const roomGames = await gameQueries.findGameByRoom(roomId);
|
|
|
|
const body = {currentRoom, messages, roomGames};
|
2020-01-22 00:01:35 +00:00
|
|
|
res.status(200).json(body);
|
|
|
|
}
|
2020-05-12 01:18:42 +00:00
|
|
|
catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
res.status(500).json(e);
|
2020-01-22 00:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 23:42:45 +00:00
|
|
|
module.exports = {
|
2020-01-22 00:01:35 +00:00
|
|
|
getAll,
|
|
|
|
show
|
2020-01-18 23:42:45 +00:00
|
|
|
}
|