/**
 * Created by jimiz on 2017/4/16.
 */
var Project = require('../models/project');

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

module.exports = {
    save: function (req, res) {
        var data = JSON.parse(req.body.data);
        Project.save(data, function (err, message, result) {
            if (err) {
                callback(req, res, err, message, null);
            } else {
                callback(req, res, err, message, result);
            }
        });
    },
    getData: function (req, res) {
        var data = JSON.parse(req.body.data);
        Project.getData(data.project_id, function (err, message, result) {
            if (!err) {
                callback(req, res, err, message, result);
            } else {
                callback(req, res, err, message, null);
            }
        });
    }
};