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

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