2016-11-01 20:51:30 +00:00
|
|
|
import mongoose from 'mongoose';
|
2016-12-21 19:45:45 +00:00
|
|
|
import validator from 'validator';
|
2019-10-08 14:57:10 +00:00
|
|
|
import baseModel from '../libs/baseModel';
|
2016-11-01 20:51:30 +00:00
|
|
|
|
2019-10-08 14:57:10 +00:00
|
|
|
export const schema = new mongoose.Schema({
|
2016-11-01 20:51:30 +00:00
|
|
|
planId: String,
|
2016-12-21 19:45:45 +00:00
|
|
|
subscriptionId: String,
|
2019-10-08 14:57:10 +00:00
|
|
|
owner: { $type: String, ref: 'User', validate: [v => validator.isUUID(v), 'Invalid uuid.'] },
|
|
|
|
|
quantity: { $type: Number, default: 1 },
|
2017-02-02 00:39:37 +00:00
|
|
|
paymentMethod: String, // enum: ['Paypal', 'Stripe', 'Gift', 'Amazon Payments', 'Google', '']}
|
2016-11-01 20:51:30 +00:00
|
|
|
customerId: String, // Billing Agreement Id in case of Amazon Payments
|
|
|
|
|
dateCreated: Date,
|
|
|
|
|
dateTerminated: Date,
|
|
|
|
|
dateUpdated: Date,
|
2019-10-08 14:57:10 +00:00
|
|
|
extraMonths: { $type: Number, default: 0 },
|
|
|
|
|
gemsBought: { $type: Number, default: 0 },
|
|
|
|
|
mysteryItems: { $type: Array, default: () => [] },
|
2019-06-10 20:37:30 +00:00
|
|
|
lastReminderDate: Date, // indicates the last time a subscription reminder was sent
|
2016-11-01 20:51:30 +00:00
|
|
|
lastBillingDate: Date, // Used only for Amazon Payments to keep track of billing date
|
2017-02-02 00:39:37 +00:00
|
|
|
additionalData: mongoose.Schema.Types.Mixed, // Example for Google: {'receipt': 'serialized receipt json', 'signature': 'signature string'}
|
|
|
|
|
nextPaymentProcessing: Date, // indicates when the queue server should process this subscription again.
|
|
|
|
|
nextBillingDate: Date, // Next time google will bill this user.
|
2016-11-01 20:51:30 +00:00
|
|
|
consecutive: {
|
2019-10-08 14:57:10 +00:00
|
|
|
count: { $type: Number, default: 0 },
|
|
|
|
|
offset: { $type: Number, default: 0 }, // when gifted subs, offset++ for each month. offset-- each new-month (cron). count doesn't ++ until offset==0
|
|
|
|
|
gemCapExtra: { $type: Number, default: 0 },
|
|
|
|
|
trinkets: { $type: Number, default: 0 },
|
2016-11-01 20:51:30 +00:00
|
|
|
},
|
|
|
|
|
}, {
|
|
|
|
|
strict: true,
|
|
|
|
|
minimize: false, // So empty objects are returned
|
|
|
|
|
_id: false,
|
2018-10-28 14:23:41 +00:00
|
|
|
typeKey: '$type', // So that we can use fields named `type`
|
2016-11-01 20:51:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
schema.plugin(baseModel, {
|
2017-02-02 00:39:37 +00:00
|
|
|
private: ['additionalData'],
|
2016-11-01 20:51:30 +00:00
|
|
|
noSet: ['_id'],
|
|
|
|
|
timestamps: false,
|
2016-11-16 20:44:47 +00:00
|
|
|
_id: false,
|
2016-11-01 20:51:30 +00:00
|
|
|
});
|
|
|
|
|
|
2019-10-08 14:57:10 +00:00
|
|
|
export const model = mongoose.model('SubscriptionPlan', schema);
|