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

41 lines
1 KiB
JavaScript
Raw Permalink 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
}
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
}
}
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
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);
}
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
module.exports = {
getAll,
show
2020-01-18 23:42:45 +00:00
}