/**
 * Created by zhang on 2018/9/12.
 */

let materialFacade = require('../facade/material_replace_facade');
let logger = require("../../../logs/log_helper").logger;
let controller = {
    getMaterial:async function(req) {
        let data = req.body.data;
        return await materialFacade.findMaterial(JSON.parse(data),req.session.sessionCompilation._id);

    },
    replace:async function(req){
        let data = req.body.data;
        return await materialFacade.replace(JSON.parse(data));
    },
};

module.exports ={
    action:async function(req,res){//自动跳转到URL对应的controller方法
        let result={
            error:0
        };
        try {
            let functionName = req.url.replace(/\//g,"");
            result.data = controller[functionName]?await controller[functionName](req):"";
        }catch (err){
            logger.err(err);
            result.error=1;
            result.message = err.message;
        }
        res.json(result);
    }
};