{"size": 879, "ext": "js", "max_stars_repo_path": "routes/createRoom.js", "max_stars_repo_name": "websterbei/wecode", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "routes/createRoom.js", "max_issues_repo_name": "websterbei/wecode", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "routes/createRoom.js", "max_forks_repo_name": "websterbei/wecode", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.3, "max_line_length": 89, "alphanum_fraction": 0.638225256}
var express = require('express');
var path = require('path');
var Redis = require('ioredis');
var router = express.Router();

function roomInitialize(redis, roomName) {
  var key = 'rooms:'+roomName;
  redis.set(key, true);
  redis.expire(key, 604800); //The code room will exist for seven days without logging in
}

router.post('/', function(req, res, next) {
  var roomName = req.body.roomName;
  var redis = new Redis(6379, 'wecode.datinker.com');
  redis.exists('rooms:'+roomName, function(err, result) {
    if(err) res.send({status: false, reason: 'Internal Error'});
    else if(result) res.send({status: false, reason: 'Room Already Exists'});
    else {
      try {
        roomInitialize(redis, roomName);
        res.send({status: true, reason: null});
      } catch(e) {
        res.send({status: false, reason: e});
      }
    }
  });
});

module.exports = router;
