Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 我可以使用区段与nodejsmongoose创建一个子类吗?_Node.js_Class_Mongoose_Subclass - Fatal编程技术网

Node.js 我可以使用区段与nodejsmongoose创建一个子类吗?

Node.js 我可以使用区段与nodejsmongoose创建一个子类吗?,node.js,class,mongoose,subclass,Node.js,Class,Mongoose,Subclass,我甚至还上过课。我想做的是使用构造函数。 我想创建一个子类 ex) 我的代码: 我创建了一个类并在模式上运行loadClass。但是我想让OrderLog成为一个结构,当我第一次调用这个类时,它使用构造函数返回子类 const { Schema } = require('mongoose'); const orderLogSchema = new Schema({ userId: {type: String, required: false, index: true}, ord

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

ex)

我的代码:

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

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

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


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;
};
const { Schema } = require('mongoose');

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


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;
};