'use strict';

/**
 * 标准库控制器基类
 *
 * @author Mai
 * @date 2018/3/13
 * @version
 */


const BaseController = require('../base/base_controller');


class StandardLibController extends BaseController {

    /**
     * 构造函数
     *
     * @param {Object} ctx - egg全局变量
     * @param {Object} model - 标准库名称
     * @return {void}
     */
    constructor(ctx, model) {
        super(ctx);
        this.model = model;
        this.app = null;
    }

    async getData(ctx) {
        const responseData = {
            err: 0,
            msg: '',
            data: [],
        };
        try {
            const data = JSON.parse(ctx.request.body.data);
            if (isNaN(data.list_id) || data.list_id <= 0) {
                throw '参数错误';
            }
            const libData = await this.model.getData(data.list_id);

            responseData.data = libData;
        } catch (error) {
            responseData.err = 1;
            responseData.msg = error;
        }

        ctx.body = responseData;
    }

}

module.exports = StandardLibController;