Skip to content
Jin Li edited this page Mar 4, 2016 · 6 revisions

collection name

EF-Class

admin base - schema

Schema.Class = {
    name : KG.schema.default({
        optional : true
    }),

    programID : KG.schema.default(),
    sessionID : KG.schema.default(),
    status : KG.schema.default({
        allowedValues: Schema.const.status
    }),
    length : KG.schema.default(),
    level : KG.schema.default({
        allowedValues : Schema.const.level,
        defaultValue : 'Beginner'
    }),
    teacher : KG.schema.default({}),
    schedule : {
        type : new SimpleSchema(Schema.ClassSchedule)
    },
    tuition : {
        type : new SimpleSchema(Schema.ClassTuition)
    },
    numberOfClass : KG.schema.default({
        type : Number,
        label : 'Number Of Class',
        custom : function(){
            if(this.value < 1){
                return 'NumberOfClassLess';
            }
        }
    }),
    maxStudent : KG.schema.default({
        type : Number,
        label : 'Maximum Student',
        custom : function(){
            let min = this.field('minStudent');
            //console.log(min, this.value);
            if(this.value < min.value){
                //throw new Error('max student is must more than minimum student');
                return 'MinStudentMoreThanMaxStudent';
            }

        }
    }),
    minStudent : KG.schema.default({
        defaultValue : 0,
        type : Number,
        label : 'Minimum Student'
    }),
    trialStudent : KG.schema.default({
        defaultValue : 0,
        type : Number,
        label : 'Trial Student'
    }),
    makeupStudent : KG.schema.default({
        defaultValue : 0,
        optional : true,
        type : Number,
        label : 'Makeup Student'
    }),
    makeupClassFee : KG.schema.default({
        type : Number,
        optional : true,
        defaultValue : 0
    }),

    minAgeRequire : KG.schema.default({
        type : Number,
        defaultValue : 0,
        optional : true,
        label : 'Minimum Age'
    }),
    maxAgeRequire : KG.schema.default({
        type : Number,
        optional : true,
        label : 'Maximum Age'
    }),
    genderRequire : KG.schema.default({
        allowedValues : Schema.const.genderRequire,
        defaultValue : 'All'
    }),

    createTime : KG.schema.createTime(),
    updateTime : KG.schema.updateTime()
};

Schema.ClassSchedule = {
    day : KG.schema.default({
        allowedValues : Schema.const.day
    }),
    time : KG.schema.default()
};
Schema.ClassTuition = {
    type : KG.schema.default({
        allowedValues : Schema.const.tuitionType
    }),
    money : KG.schema.default({
        label : 'Tuition money'
    })
};

Schema.const = {
    day : ['Sun', 'Mon', 'Tues', 'Wed', 'Thu', 'Fri', 'Sat'],
    tuitionType : ['each', 'total'],
    status : ['Active', 'Inactive'],
    level : ['Beginner', 'Intermediate', 'Advanced'],
    genderRequire : ['All', 'Male', 'Female'],
    //length : ['30 min', '45 min', '1 hr', '1.5 hr', '2 hr']

    registrationStatus : ['trail', 'register', 'wait']
};

mobile Base schema

{
    name: {
        type: String
    },
    programID: {
        type: String,
        optional: false

    },
    sessionID: {
        type: String,
        optional: false
    },
    status: {
        type: String,
        allowedValues: ['Active', 'Inactive'],
        defaultValue: "Active"
    },
    length: {
        type: String,
        optional: false
    },

    levels: {
        type: [String],
        allowedValues: ['Beginner', 'Intermediate', 'Advanced'],
        defaultValue: 'Beginner',
        optional: false
    },
    teacher: {
        type: String,
        optional: true
    },

    schedule: {
        type: new SimpleSchema({
            day: {
                type: String,
                allowedValues: ['Sun', 'Mon', 'Tues', 'Wed', 'Thu', 'Fri', 'Sat'],
                optional: false
            },
            time: {
                type: String,
                optional: false
            }
        }),
        optional: false
    },

    tuition: {
        type: new SimpleSchema({
            type: {
                type: String,
                allowedValues: ['each', 'total']
            },
            money: {
                type: String,
                label: 'Tuition money'
            }
        })
    },
    maxStudent: {
        type: Number,
        label: 'Maximum Student',
        custom: function () {
            let min = this.field('minStudent');
            //console.log(min, this.value);
            if (this.value < min.value) {
                //throw new Error('max student is must more than minimum student');
                return 'max student is must more than minimum student!';
            }

        }
    },

    minStudent: {
        defaultValue: 0,
        type: Number,
        label: 'Minimum Student',
        custom: function () {
            let max = this.field('maxStudent');
            //console.log(min, this.value);
            if (this.value > max.value) {
                //throw new Error('min student is must less than max student');
                return 'Min student is must less than max student!';
            }
        }
    },
    trialStudent: {
        defaultValue: 0,
        type: Number,
        label: 'Trial Student'
    },

    makeupStudent :{
        defaultValue : 0,
        optional : true,
        type : Number,
        label : 'Makeup Student'
    },

    makeupClassFee : {
        type : Number,
        optional : true,
        defaultValue : 0
    },

    minAgeRequire: {
        type: Number,
        defaultValue: 0,
        optional: true,
        label: 'Minimum Age'
    },
    maxAgeRequire: {
        type: Number,
        optional: true,
        label: 'Maximum Age'
    },
    genderRequire: {
        allowedValues: ['All', 'Male', 'Female'],
        defaultValue: 'All'
    },

    createTime: {
        type: Date,
        optional: true,
        autoValue: function () {
            if (this.isInsert) {
                return new Date();
            }
        }
    },
    updateTime: {
        type: Date,
        optional: true,
        autoValue: function () {
            if (this.isInsert) {
                return new Date();
            }
            if (this.isUpdate) {
                return new Date();
            }
        }
    }
}