/**
 * Created by Tony on 2017/7/5.
 */

import mongoose from "mongoose";
import rpt_util from "../util/rpt_util";
let Rpt_Map_Fld_Mdl = mongoose.model('rpt_mapping_field');


//统一回调函数
let callback = function(req, res, err, message, data){
    res.json({error: err, message: message, data: data});
};

module.exports = {
    getReportUserCfg: function(req, res){
        let userId = req.body.userId;
        rpt_util.getReportCacheByUser(userId, function(rst_cfg){
            callback(req,res,false,"", rst_cfg);
        });
    },

    getAllMappingFields: function (req, res) {
        Rpt_Map_Fld_Mdl.find({}, '-_id', {sort: {'seq': 1}}, function(err, mapFields){
            if(mapFields.length){
                if (err) {
                    callback(req,res,true,"no mapping fields were found!", mapFields);
                } else {
                    callback(req,res,false,"", mapFields);
                }
            }
        })

    }
};
