12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 'use strict';
- /**
- * 标准清单控制器
- *
- * @author Mai
- * @date 2018/3/13
- * @version
- */
- const StandardLibController = require('./standard_lib_controller');
- module.exports = app => {
- class StdChapterController extends StandardLibController {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx, ctx.service.stdChapter);
- this.app = app;
- }
- /**
- * 根据id获取子项
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async getChildren(ctx) {
- const responseData = {
- err: 0,
- msg: '',
- data: [],
- };
- try {
- const data = JSON.parse(ctx.request.body.data);
- if (isNaN(data.chapter_id) || data.chapter_id <= 0 || isNaN(data.list_id) || data.list_id <= 0) {
- throw '参数错误';
- }
- const condition = { pid: data.chapter_id, list_id: data.list_id };
- const libData = await this.model.getAllDataByCondition({ where: condition });
- responseData.data = libData;
- } catch (error) {
- responseData.err = 1;
- responseData.msg = error;
- }
- ctx.body = responseData;
- }
- }
- return StdChapterController;
- };
|