/**
 * 评分表 
 * 用于存储评分规则
 * 
 */

import {Schema} from 'mongoose';
import { baseDB } from '../../db/mongo/dbInit';

const gradeSchema = new Schema({
    
});

var gradeModel;
export function initModel(){
    gradeModel = baseDB.model('grade', gradeSchema);
    gradeModel.selectOnceData = async function (paramater:object) {
        let selectInfo = await gradeModel.findOne(paramater).exec();
        if (selectInfo) {
            if (!selectInfo.runSave) {
                selectInfo.runSave = selectInfo.save;
                selectInfo.save = save.bind(selectInfo)
            }
        }
        return selectInfo;
    }
}
export async function save(throwError=false) {
    if (!this.isModified()) return;
    await this.runSave({validateBeforeSave:false}).catch(err=>{
        console.log(err);
    });
}