{"size": 1186, "ext": "js", "max_stars_repo_path": "packages/custom/books/server/controllers/papers.js", "max_stars_repo_name": "shouliang/hapihu", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/custom/books/server/controllers/papers.js", "max_issues_repo_name": "shouliang/hapihu", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/custom/books/server/controllers/papers.js", "max_forks_repo_name": "shouliang/hapihu", "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": 25.2340425532, "max_line_length": 67, "alphanum_fraction": 0.4713322091}
'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    Paper = mongoose.model('Paper'),
    _ = require('lodash'),
    async = require('async');

var http = require('http');


module.exports = function () {
    var Subject=mongoose.model('Subject');
    return {
        /**
         * subject
         */
        subject:function (req,res,next,id) {
            Subject.findOne({_id:id}, function (err, result) {
                if (err) return next(err);
                if (!result) return next('科目不存在');
                req.subject = result;
                next();
            });
        },
        /**
         * 根据stage 获取subject
         */
        getSubject:function (req,res) {
            if(req.subject){
                return res.json({result:1,data:req.subject});
            }
            var stageId=req.query.stage;
            if(!stageId){
                return res.status(400).send('缺少参数');
            }
            Subject.find({stageId:stageId},function (err,results) {
               if(err) res.status(400).send('数据库访问失败');
                return res.json({result:1,data:results});
            });

        }
       
    };
}