/**
 * Created by Zhong on 2017/12/21.
 */

import BaseController from '../../common/base/base_controller';
import SectionTreeDao from '../models/sectionTreeModel';

let sectionTreeDao = new SectionTreeDao();
let callback = function (req, res, err, msg, data) {
    res.json({error: err, message: msg, data: data});
};

class CompleSectionTreeController extends BaseController{
    //保证章节树ID唯一,标准树与补充树才可进行拼接
    getNewTreeID(req, res){
        sectionTreeDao.getNewTreeID(function (err, data) {
            callback(req, res, err, '', data);
        });
    }

    getRationTree(req, res){
        let data = JSON.parse(req.body.data);
        sectionTreeDao.getRationTree(req.session.sessionUser.id, req.session.sessionCompilation._id, data.rationRepId, data.type, function (err, data) {
            callback(req, res, err, '', data);
        });
    }

    updateRationSection(req, res){
        let data = JSON.parse(req.body.data);
        sectionTreeDao.updateSection(req.session.sessionUser.id, req.session.sessionCompilation._id, data.updateData, function (err, data) {
            callback(req, res, err, '', data);
        });
    }
}

export default CompleSectionTreeController;