RLibMapController.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Created by Syusuke on 2017/3/20.
  3. */
  4. var rationLibData = require('../models/rationLibMap');
  5. var callback = function(req,res,err,data){
  6. if(data){
  7. res.status(200)
  8. res.json({success:true,data:data});
  9. }
  10. else
  11. if(err){
  12. res.status(500)
  13. res.json({success:false,error:err});
  14. }
  15. else{
  16. res.status(204);
  17. res.json({success:true});
  18. }
  19. }
  20. module.exports ={
  21. addRationLib:function(req,res){
  22. var libName = req.body.rationDisPlayName;
  23. rationLibData.addRationLib(libName,function(err,data){
  24. if (data) {
  25. callback(req, res, err, data);
  26. } else {
  27. callback(req, res, err, null);
  28. }
  29. })
  30. },
  31. getRealLibName:function(req,res){
  32. var libName = req.body.rationName;
  33. rationLibData.getRealLibName(libName,function(err,data){
  34. if (data) {
  35. callback(req, res, err, data);
  36. } else {
  37. callback(req, res, err, null);
  38. }
  39. })
  40. },
  41. getDisPlayRationLibs: function(req, res){
  42. rationLibData.getDisplayRationLibs(function(err, data){
  43. if (data) {
  44. callback(req, res, err, data);
  45. } else {
  46. callback(req, res, err, null);
  47. }
  48. });
  49. },
  50. deleteRationLib:function(req,res){
  51. var rationName = req.body.rationName;
  52. rationLibData.deleteRationLib(rationName,function(err,data){
  53. if (data) {
  54. callback(req, res, err, data);
  55. } else {
  56. callback(req, res, err, null);
  57. }
  58. })
  59. },
  60. editRationLibs:function(req,res){
  61. var rationName = req.body.rationName;
  62. var newName = req.body.newName;
  63. rationLibData.editRationLib(rationName,newName,function(err,data){
  64. if (data) {
  65. callback(req, res, err, data);
  66. } else {
  67. callback(req, res, err, null);
  68. }
  69. })
  70. }
  71. }