Класс Mongoose ES6 со статическими средствами получения

#javascript #mongoose #ecmascript-6

#javascript #mongoose #ecmascript-6

Вопрос:

Есть ли какой-либо способ получить доступ к статическому средству получения в классе ES6, загруженном с помощью Mongoose?

В моем приведенном ниже коде я хочу иметь доступ к статическому средству получения «STATUS» через модель mongoose.

 const STATUS = {
    PRE_ACTIVE: 'pre-active',
    LIVE: 'live',
};

class Student {
    static get STATUS() {
        return STATUS;
    }

    static attributes() {
        return {
            name: {type: String, required: true},
            lastName: {type: String, required: true},
            language: {type: String, required: true},
            gender: {type: String, required: true},
        }
    }

    get fullName() {
        return `${this.name}_${this.lastName}`;
    }
}
const schema = new Schema(Student.attributes(), {timestamps: true});
schema.loadClass(Student);

const StudentMongoose = mongoose.model('Student', schema);
StudentMongoose.find({}); // -> OK

const instance = new StudentMongoose({name: 'John', lastName: 'Doe', language: 'en', gender: 'male'});
instance.fullName; // -> OK

StudentMongoose.attributes(); // -> OK

StudentMongoose.STATUS; // -> NOK  

Комментарии:

1. StudentMongoose != Student . Почему бы просто не использовать Student.STATUS ?

2. Потому что я хочу экспортировать только StudentMongoose (как Student). Чтобы я не ходил с двумя объектами.

3. @MiguelSantos ты нашел что-нибудь?

4. @HRK44 нет, ничего.

5. Ну, вы могли бы просто реализовать, STATUS как вы реализовали attributes . Разница чисто семантическая…