const mongoose = require('mongoose'), Schema = mongoose.Schema, { SubType } = require('./subscription'); const schema = new Schema({ userId: { type: Schema.Types.ObjectId, ref: 'User', index: true, required: true }, subType: { type: { type: String, enum: { values: Object.values(SubType), message: '{VALUE} for subscription \'type\' is not supported' } } }, periodStart: { type: Number, require: true }, periodEnd: { type: Number, require: true }, custId: { type: String }, // Stripe customer Id lookupKey: { type: String }, // The lookup key for the price used within the subscription in the billing period }); schema.index({ custId: 1, subType: 1 }); module.exports = mongoose.model('Bill_Period', schema);