project_controller.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Created by jimiz on 2017/4/16.
  3. */
  4. var Project = require('../models/project');
  5. let logger = require('../../../logs/log_helper').logger;
  6. //统一回调函数
  7. var callback = function(req, res, err, message, data){
  8. res.json({error: err, message: message, data: data});
  9. };
  10. module.exports = {
  11. save: function (req, res) {
  12. var data = JSON.parse(req.body.data);
  13. console.log(data);
  14. Project.save(data, function (err, message, result) {
  15. if (err) {
  16. logger.err(err);
  17. callback(req, res, err, message, null);
  18. } else {
  19. callback(req, res, err, message, result);
  20. }
  21. });
  22. },
  23. getData: function (req, res) {
  24. var data = JSON.parse(req.body.data);
  25. Project.getData(data.project_id, function (err, message, result) {
  26. if (!err) {
  27. callback(req, res, err, message, result);
  28. } else {
  29. callback(req, res, err, message, null);
  30. }
  31. });
  32. }
  33. };