ration_repository_controller.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * Created by Tony on 2017/4/20.
  3. */
  4. var rationRepository = require("../models/repository_map");
  5. var callback = function(req, res, err, message, data){
  6. res.json({error: err, message: message, data: data});
  7. };
  8. module.exports = {
  9. addRationRepository:function(req,res){
  10. var rationObj = JSON.parse(req.body.rationRepObj);
  11. rationRepository.addRationRepository(rationObj,function(err,data){
  12. if (data) {
  13. callback(req, res, err, "has data", data);
  14. } else {
  15. callback(req, res, err, "no data", null);
  16. }
  17. })
  18. },
  19. getDisPlayRationLibs: function(req, res){
  20. rationRepository.getDisplayRationLibs(function(err, data){
  21. if (data) {
  22. callback(req, res, err, "has data",data);
  23. } else {
  24. callback(req, res, err, "no data", null);
  25. }
  26. });
  27. },
  28. getRealLibName:function(req,res){
  29. var libName = req.body.rationName;
  30. rationRepository.getRealLibName(libName,function(err,data){
  31. if (data) {
  32. callback(req, res, err, "has data", data);
  33. } else {
  34. callback(req, res, err, "no data", null);
  35. }
  36. })
  37. },
  38. getLibIDByName:function(req,res){
  39. rationRepository.getLibIDByName(req.body.libName, function(err,data){
  40. if (data) {
  41. callback(req, res, err, "has ID", data);
  42. } else {
  43. callback(req, res, err, "no ID", null);
  44. }
  45. })
  46. },
  47. deleteRationLib:function(req,res){
  48. var rationName = req.body.rationName;
  49. rationRepository.deleteRationLib(rationName,function(err,data){
  50. if (data) {
  51. callback(req, res, err, "has data", data);
  52. } else {
  53. callback(req, res, err, "no data", null);
  54. }
  55. })
  56. },
  57. updateRationRepositoryName: function(req, res) {
  58. var orgName = req.body.rationName;
  59. var newName = req.body.newName;
  60. rationRepository.updateName(orgName, newName, function(err, data){
  61. if (data) {
  62. callback(req, res, err, "has data", data);
  63. } else {
  64. callback(req, res, err, "no data", null);
  65. }
  66. });
  67. }
  68. }