<commit_before>var express = require('express');
var mongoose = require('mongoose');
var passport = require('passport');
var router = express.Router();
var kintai_schema = module.parent.exports.kintaiSchema;
var mongoose = module.parent.exports.mongoose;

//指定された日付のデータをDBから探して返す
function CreateCalenderJson(_id, _day, _year, _month, cb){
  var day = parseInt(_day);
  var year = parseInt(_year);
  var month = parseInt(_month);
  if(isNaN(day) || isNaN(year) || isNaN(month) ){ 
    console.log({error:{msg:"Invalied required." ,status:400}});
    cb();
  }
  var model = mongoose.model( _id, kintai_schema);
  var tmp = { };
  model.find(
    {// query
      year : year,
      month: month,
      day  : day
    },{// view
      _id         : 0
      ,startTime  : 1
      ,stopTime   : 1
      ,registType : 1
      ,registTime : 1
    },{// option
      sort:{created: -1},
      //limit: 1
    }, function(err, result){
      if(err) console.log(err)
      cb(result);
      return tmp;
  });
}

/* GET users listing. */
router.get('/:year/:month', function(req, res) {
  if(
    !req.params.year.match(/^[0-9]{4}$/) ||
    !req.params.month.match(/^[0-9]{2}$/)
  ){ res.json({ message : "invaled request" }); }
  var year  = parseInt(req.params.year);
  var month = parseInt(req.params.month);
  var dat   = new Date(month.toString() + "-01-" + year.toString());
  // Monthの設定は0-11
  dat.setMonth(month);
  dat.setDate(0);
  var result = {
    year : req.params.year,
    month: req.params.month,
    day: {}
  };
  for( i = 1; i <= dat.getDate(); i++){
    result.day[i.toString()] = {};
  }
  Object.keys(result.day).forEach(function(day, index){
    CreateCalenderJson(req.session.passport.user.id, day, req.params.year, req.params.month, function(days){
      console.log(day, Object.keys(result.day).length);
      result.day[day.toString()] = days;
      if(day === Object.keys(result.day).length)
        res.json(result);
    });
  });
});

router.get('/:year/:month/:day', function(req, res) {
  if(
    !req.params.year.match(/^[0-9]{4}$/) ||
    !req.params.month.match(/^[0-9]{2}$/)||
    !req.params.day.match(/^[0-9]{2}$/)
  ){ res.redirect("/"); }
  var year = parseInt(req.params.year);
  var month= parseInt(req.params.month);
  var day  = parseInt(req.params.day);<commit_msg>console<commit_after>var express = require('express');
var mongoose = require('mongoose');
var passport = require('passport');
var router = express.Router();
var kintai_schema = module.parent.exports.kintaiSchema;
var mongoose = module.parent.exports.mongoose;

//指定された日付のデータをDBから探して返す
function CreateCalenderJson(_id, _day, _year, _month, cb){
  var day = parseInt(_day);
  var year = parseInt(_year);
  var month = parseInt(_month);
  console.log(year,month,day);
  if(isNaN(day) || isNaN(year) || isNaN(month) ){ 
    console.log({error:{msg:"Invalied required." ,status:400}});
    cb();
  }
  var model = mongoose.model( _id, kintai_schema);
  var tmp = { };
  model.find(
    {// query
      year : year,
      month: month,
      day  : day
    },{// view
      _id         : 0
      ,startTime  : 1
      ,stopTime   : 1
      ,registType : 1
      ,registTime : 1
    },{// option
      sort:{created: -1},
      //limit: 1
    }, function(err, result){
      if(err) console.log(err)
      cb(result);
      return tmp;
  });
}

/* GET users listing. */
router.get('/:year/:month', function(req, res) {
  if(
    !req.params.year.match(/^[0-9]{4}$/) ||
    !req.params.month.match(/^[0-9]{2}$/)
  ){ res.json({ message : "invaled request" }); }
  var year  = parseInt(req.params.year);
  var month = parseInt(req.params.month);
  var dat   = new Date(month.toString() + "-01-" + year.toString());
  // Monthの設定は0-11
  dat.setMonth(month);
  dat.setDate(0);
  var result = {
    year : req.params.year,
    month: req.params.month,
    day: {}
  };
  for( i = 1; i <= dat.getDate(); i++){
    result.day[i.toString()] = {};
  }
  console.log(result);
  Object.keys(result.day).forEach(function(day, index){
    CreateCalenderJson(req.session.passport.user.id, day, req.params.year, req.params.month, function(days){
      console.log(day, Object.keys(result.day).length);
      result.day[day.toString()] = days;
      if(day === Object.keys(result.day).length)
        res.json(result);
    });
  });
});

router.get('/:year/:month/:day', function(req, res) {
  if(
    !req.params.year.match(/^[0-9]{4}$/) ||
    !req.params.month.match(/^[0-9]{2}$/)||
    !req.params.day.match(/^[0-9]{2}$/)
  ){ res.redirect("/"); }
  var year = parseInt(req.params.year);
  var month= parseInt(req.params.month);
  var day  = parseInt(req.params.day);
{'fraction_non_alphanumeric': 0.19870967741935483, 'fraction_numerical': 0.013763440860215054, 'mean_word_length': 2.999140154772141, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2435773', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1714, 'n_words': 305}