/**
 * 计算程序标准库业务模型
 *
 * @author CaiAoLin
 * @date 2017/10/23
 * @version
 */
import BaseModel from "../base/base_model";
import mongoose from "mongoose";

class STDCalcProgramModel extends BaseModel {

    /**
     * 构造函数
     *
     * @return {void}
     */
    constructor() {
        let parent = super();
        parent.model = mongoose.model("std_calc_programs");
        parent.init();
    }

    /**
     * 获取计算程序列表
     *
     * @return {Promise}
     */
    async getProgramList(compilationId) {
        let result = [];
        let field = {ID: 1, libName: 1,displayName:1};
        let programList = await this.findDataByCondition({compilationId:compilationId,ID: {$ne: ''}}, field, false);

        if (programList === null) {
            return result;
        }
        // 整理数据
        for(let program of programList) {
            let tmpData = {
                id: program.ID,
                name: program.libName,
                displayName:program.displayName
            };
            result.push(tmpData);
        }
        return result;
    }

}

export default STDCalcProgramModel;
