{"size": 2209, "ext": "js", "max_stars_repo_path": "src/controllers/studentControllers.js", "max_stars_repo_name": "MrsZQJ/heima27_node_zqj", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/controllers/studentControllers.js", "max_issues_repo_name": "MrsZQJ/heima27_node_zqj", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/controllers/studentControllers.js", "max_forks_repo_name": "MrsZQJ/heima27_node_zqj", "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": 31.5571428571, "max_line_length": 85, "alphanum_fraction": 0.5491172476}
const path = require('path');
const template = require('art-template');
const databasetool = require(path.join(__dirname, '../tools/databasetool.js'));
exports.list = (req, res) => {
    const keywords = req.query.keywords || '';
    databasetool.find('studentInfo', {
        name: {
            $regex: keywords
        }
    }, (err, docs) => {
        console.log(docs);
        var html = template(path.join(__dirname, '../public/html/list.html'), {
            student: docs,
            keywords
        });
        res.send(html);
    })
}
exports.add = (req, res) => {
    const html = template(path.join(__dirname, '../public/html/add.html'), {});
    // console.log(html);
    res.send(html);
}
exports.add2 = (req, res) => {
    databasetool.insertSingle('studentInfo', req.body, (err, result) => {
        if (!result) {
            res.send(`<script>alert("添加失败!")</script>`)
            return;
        }
        res.send(`<script>location="/studentmanager/list"</script>`)
    })
}
exports.edit = (req, res) => {
    const _id = databasetool.ObjectId(req.params.studyId);
    // console.log(_id);
    // res.send('12345667');
    databasetool.findOne('studentInfo', {
        _id
    }, (err, doc) => {
        console.log(doc);
        const html = template(path.join(__dirname, '../public/html/edit.html'), doc);
        res.send(html);
    })
}
exports.edit2 = (req, res) => {
    const _id = databasetool.ObjectId(req.params.studyId);
    console.log(_id);
    databasetool.updataOne('studentInfo', {
        _id
    }, req.body, (err, result) => {
        if (result.modifiedCount !== 1) {
            res.send('<script>alert("修改失败!")</script>');
        } else {
            res.send('<script>location="/studentmanager/list"</script>');
        }
    })
}
exports.deleteStudent = (req, res) => {
    const _id = databasetool.ObjectId(req.params.studyId);
    console.log(_id);
    databasetool.deleteYige('studentInfo', {_id}, (err, result) => {
        if(!result) {
            res.send(`<script>alert("删除失败!")</script>`);
        } else {
            res.send(`<script>location.href='/studentmanager/list'</script>`);
            // console.log(11111);
            
        }
    })
}