std_chapter_controller.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. /**
  3. * 标准清单控制器
  4. *
  5. * @author Mai
  6. * @date 2018/3/13
  7. * @version
  8. */
  9. const StandardLibController = require('./standard_lib_controller');
  10. module.exports = app => {
  11. class StdChapterController extends StandardLibController {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx, ctx.service.stdChapter);
  20. this.app = app;
  21. }
  22. /**
  23. * 根据id获取子项
  24. *
  25. * @param {Object} ctx - egg全局变量
  26. * @return {void}
  27. */
  28. async getChildren(ctx) {
  29. const responseData = {
  30. err: 0,
  31. msg: '',
  32. data: [],
  33. };
  34. try {
  35. const data = JSON.parse(ctx.request.body.data);
  36. if (isNaN(data.chapter_id) || data.chapter_id <= 0 || isNaN(data.list_id) || data.list_id <= 0) {
  37. throw '参数错误';
  38. }
  39. const condition = { pid: data.chapter_id, list_id: data.list_id };
  40. const libData = await this.model.getAllDataByCondition({ where: condition });
  41. responseData.data = libData;
  42. } catch (error) {
  43. responseData.err = 1;
  44. responseData.msg = error;
  45. }
  46. ctx.body = responseData;
  47. }
  48. }
  49. return StdChapterController;
  50. };