{"size": 656, "ext": "js", "max_stars_repo_path": "controllers/junction_controller.js", "max_stars_repo_name": "indyminhas/DrawScape", "max_stars_repo_stars_event_min_datetime": "2020-08-03T00:43:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-03T00:43:24.000Z", "max_issues_repo_path": "controllers/junction_controller.js", "max_issues_repo_name": "indyminhas/DrawScape", "max_issues_repo_issues_event_min_datetime": "2020-07-28T04:22:33.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-02T14:28:06.000Z", "max_forks_repo_path": "controllers/junction_controller.js", "max_forks_repo_name": "indyminhas/DrawScape", "max_forks_repo_forks_event_min_datetime": "2020-07-30T04:55:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-30T04:55:53.000Z"}
{"max_stars_count": 1, "max_issues_count": 8, "max_forks_count": 1, "avg_line_length": 27.3333333333, "max_line_length": 88, "alphanum_fraction": 0.625}
const express = require("express");

const router = express.Router();

const db = require("../models");


//find all where rooms where this user belongs
router.get('/api/junctiontable/:roomId', (req, res) => {
    db.Room.findAll({ where: { id: req.params.roomId }, include: db.User }).then(data =>
        res.json(data)
    ).catch(err => {
        res.status(500).end();
    });
});

// add a player (non-owner) to a room
router.post('/api/junctiontable/:roomId', async (req, res) => {
    let room = await db.Room.findOne({ where: { id: req.params.roomId } });
    room.addPlayroom(req.session.user.id);
    res.json(room)
});

module.exports = router;