我可以使用扩展区使用Nodejs猫鼬创建子类吗?

问题描述

我什至上过课。我想做的是使用构造函数。 我想创建一个子类。

ex)

class OrderLog {
        constructor(...args) {
           switch (this.planType) { 
            case 'test':
               // return new SubClass()  // // I want to return the subclass by condition
                break;
           }
         }
}

我的代码

我创建了一个类,并在模式上运行了loadClass。但是我想使OrderLog成为一个结构,该结构在我第一次调用类时使用构造函数返回子类。

const { Schema } = require('mongoose');

const orderLogSchema = new Schema({
    userId: {type: String,required: false,index: true},orderPlanId: {type: String,orderId: {type: String,planType: {type: String,required: true,indicatorType: {type: String},bundle: {type: String},action: {type: String,required: true},orderContents: {type: String},createdAt: {type: Date,});


class OrderLog {
    constructor(...args) {
    }

    static makeNew(orderLogForm){
        const saveOrderLogForm = {
            userId: orderLogForm.userId,orderPlanId: orderLogForm.orderPlanId,orderId: orderLogForm.id,planType: orderLogForm.planType,indicatorType: orderLogForm.indicatorType,bundle: orderLogForm.bundle,action: orderLogForm.action,orderContents: orderLogForm.orderContents,createdAt: orderLogForm.createdAt
        };
        const orderLog = new this(saveOrderLogForm)
        orderLog.save();
    }
}

orderLogSchema.loadClass(OrderLog);


module.exports = (connectionPool) => {
    let orderLogModel = connectionPool.model('OrderLog',orderLogSchema);
    return orderLogModel;
};

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)