search_controller.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Created by Mai on 2017/6/5.
  3. */
  4. var rationItem = require('../models/ration_item');
  5. let rationChapter = require('../models/ration_section_tree');
  6. var callback = function(req, res, err, message, data){
  7. res.json({error: err, message: message, data: data});
  8. };
  9. module.exports = {
  10. getRationItem: function (req, res) {
  11. let rId = req.body.rationLibId, code = req.body.code;
  12. rationItem.getRationItem(rId, code).then(function (result) {
  13. let rationData = JSON.stringify(result._doc);
  14. rationData = JSON.parse(rationData);
  15. console.log(rationData);
  16. rationChapter.getRationChapter(rationData.rationRepId, rationData.sectionId).then(function (result) {
  17. rationData.chapter = result._doc;
  18. console.log(rationData);
  19. callback(req, res, null, '', rationData);
  20. }).catch(function (err, message) {
  21. console.log(rationData);
  22. callback(req, res, null, '', rationData);
  23. });
  24. }).catch(function (err, message) {
  25. callback(req, res, err, message, null);
  26. })
  27. },
  28. findRation: function (req, res) {
  29. var rId = req.body.rationLibId, keyword = req.body.keyword;
  30. rationItem.findRation(rId, keyword, function (err, message, rst) {
  31. if (err) {
  32. callback(req, res, err, message, null);
  33. } else {
  34. callback(req, res, 0, '', rst);
  35. }
  36. });
  37. }
  38. };