/**
 * Created by Tony on 2017/4/20.
 */
var rationRepository = require("../models/repository_map").Dao;

var callback = function(req, res, err, message, data){
    res.json({error: err, message: message, data: data});
};

module.exports = {
    addRationRepository:function(req,res){
        var rationObj = JSON.parse(req.body.rationRepObj);
        rationRepository.addRationRepository(rationObj,function(err,data){
            if (data) {
                callback(req, res, err, "has data", data);
            } else {
                callback(req, res, err, "no data", null);
            }
        })
    },
    getDisPlayRationLibs: function(req, res){
        rationRepository.getDisplayRationLibs(function(err, data){
            if (data) {
                callback(req, res, err, "has data",data);
            } else {
                callback(req, res, err, "no data", null);
            }
        });
    },
    getRealLibName:function(req,res){
        var libName = req.body.rationName;
        rationRepository.getRealLibName(libName,function(err,data){
            if (data) {
                callback(req, res, err, "has data", data);
            } else {
                callback(req, res, err, "no data", null);
            }
        })
    },
    getLibIDByName:function(req,res){
        rationRepository.getLibIDByName(req.body.libName, function(err,data){
            if (data) {
                callback(req, res, err, "has ID", data);
            } else {
                callback(req, res, err, "no ID", null);
            }
        })
    },
    deleteRationLib:function(req,res){
        var rationName = req.body.rationName;
        rationRepository.deleteRationLib(rationName,function(err,data){
            if (data) {
                callback(req, res, err, "has data", data);
            } else {
                callback(req, res, err, "no data", null);
            }
        })
    },
    updateRationRepositoryName: function(req, res) {
        var orgName = req.body.rationName;
        var newName = req.body.newName;
        rationRepository.updateName(orgName, newName, function(err, data){
            if (data) {
                callback(req, res, err, "has data", data);
            } else {
                callback(req, res, err, "no data", null);
            }
        });
    }
}