Node.js 我可以使用区段与nodejsmongoose创建一个子类吗?
我甚至还上过课。我想做的是使用构造函数。 我想创建一个子类 ex) 我的代码: 我创建了一个类并在模式上运行loadClass。但是我想让OrderLog成为一个结构,当我第一次调用这个类时,它使用构造函数返回子类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
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;
};