'use strict';

/**
 * 标准清单业务逻辑
 *
 * @author Mai
 * @date 2018/3/13
 * @version
 */

const StandardLib = require('./standard_lib');
module.exports = app => {

    class StdBills extends StandardLib {

        /**
         * 构造函数
         *
         * @param {Object} ctx - egg全局变量
         * @return {void}
         */
        constructor(ctx) {
            super(ctx, 'bill');
            this.dataId = 'bill_id';
            this.stdType = 'bill';
        }

        /**
         * 查询数据后，转换数据(用于兼容项目节与清单的不同)
         * @param data
         */
        convertData (data) {
            if (data instanceof Array) {
                for (const d of data) {
                    d.b_code = d.code;
                    delete d.code;
                }
            } else if (data.code) {
                data.b_code = data.code;
                delete data.code;
            }
        }

    }

    return StdBills;
};