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-21 22:33:40 +00:00
|
|
|
const {enableRoomSocket} = 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 {
|
|
|
|
// TODO eventually add check for user's private rooms
|
2020-01-18 23:49:35 +00:00
|
|
|
const publicRooms = await roomQueries.findPublicRooms();
|
2020-01-21 22:33:40 +00:00
|
|
|
enableRoomSocket(1)
|
2020-01-18 23:49:35 +00:00
|
|
|
res.status(200).json({rooms: publicRooms})
|
2020-01-18 23:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
res.status(500).json(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 00:01:35 +00:00
|
|
|
const show = async (req, res, next) => {
|
|
|
|
try {
|
|
|
|
const roomId = req.params.id;
|
|
|
|
const roomGames = await roomQueries.findRoomById(roomId);
|
2020-01-22 01:02:54 +00:00
|
|
|
const messages = await messageQueries.findMessageByRoom(roomId);
|
|
|
|
const body = {roomGames, messages};
|
2020-01-22 00:01:35 +00:00
|
|
|
res.status(200).json(body);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
res.status(500).json(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|