@positivegrid/pg-mongoose-schema 27.6.1 → 27.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/models/payment.js +38 -3
- package/package.json +1 -1
package/models/payment.js
CHANGED
|
@@ -82,7 +82,7 @@ module.exports = (mongoose) => {
|
|
|
82
82
|
}, { collection: 'jamup_product', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
83
83
|
ProductSchema.index({ sku: 1 }, { unique: true })
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
const LicenseSchema = new Schema({
|
|
86
86
|
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
87
87
|
product_id: { type: ObjectId, ref: 'Product', required: true },
|
|
88
88
|
bc_order_id: { type: Number, default: null },
|
|
@@ -106,10 +106,40 @@ module.exports = (mongoose) => {
|
|
|
106
106
|
status: { type: Number, default: 1 }, // 1:normal/2:delete/3:refund/4:trial
|
|
107
107
|
created_on: { type: Date, default: Date.now },
|
|
108
108
|
updated_on: { type: Date, default: Date.now }
|
|
109
|
-
}, { collection: 'jamup_license'
|
|
109
|
+
}, { collection: 'jamup_license' })
|
|
110
110
|
LicenseSchema.index({ iap_device_id: 1, user_id: 1, product_id: 1, status: 1 })
|
|
111
111
|
LicenseSchema.index({ user_id: 1, product_id: 1, status: 1, iap_source: 1 })
|
|
112
112
|
LicenseSchema.index({ from_redeem: 1, user_id: 1 })
|
|
113
|
+
LicenseSchema.set('toJSON', {
|
|
114
|
+
virtuals: true,
|
|
115
|
+
transform(_doc, ret) {
|
|
116
|
+
if (ret.from_free_trial && ret.from_free_trial !== null) {
|
|
117
|
+
ret.free_trial_meta = {
|
|
118
|
+
is_free_trial: true,
|
|
119
|
+
start_date: ret.created_on,
|
|
120
|
+
end_date: ret.due_date,
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
ret.free_trial_meta = null;
|
|
124
|
+
}
|
|
125
|
+
return ret
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
LicenseSchema.set('toObject', {
|
|
129
|
+
virtuals: true,
|
|
130
|
+
transform(_doc, ret) {
|
|
131
|
+
if (ret.from_free_trial && ret.from_free_trial !== null) {
|
|
132
|
+
ret.free_trial_meta = {
|
|
133
|
+
is_free_trial: true,
|
|
134
|
+
start_date: ret.created_on,
|
|
135
|
+
end_date: ret.due_date,
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
ret.free_trial_meta = null;
|
|
139
|
+
}
|
|
140
|
+
return ret;
|
|
141
|
+
}
|
|
142
|
+
})
|
|
113
143
|
|
|
114
144
|
const LicenseUpgradeMetaSchema = new Schema({
|
|
115
145
|
bc_cart_id: { type: String, required: true },
|
|
@@ -725,11 +755,16 @@ module.exports = (mongoose) => {
|
|
|
725
755
|
? 'id name sku product_type display_name extra_payment_fields created_on'
|
|
726
756
|
: 'id name sku product_type display_name addition created_on'
|
|
727
757
|
|
|
758
|
+
const freeTrialQuery = (productType === 'free_trial')
|
|
759
|
+
? { $and: [{ from_free_trial: { $ne: null } }, { from_free_trial: { $exists: true } }] }
|
|
760
|
+
: { $or: [{ from_free_trial: null }, { from_free_trial: { $exists: false } }] }
|
|
761
|
+
|
|
728
762
|
// Always check license status & due_date
|
|
729
763
|
const queryObj = _.assign({}, {
|
|
730
764
|
status: { '$in': [1, 4] },
|
|
731
765
|
'$or': [{ 'due_date': null }, { 'due_date': { $gt: new Date() } }]
|
|
732
|
-
}, query)
|
|
766
|
+
}, freeTrialQuery, query)
|
|
767
|
+
debug('getUserPurchasePromise %o', queryObj)
|
|
733
768
|
|
|
734
769
|
const result = (_.has(opts, 'isLean') && opts.isLean === true)
|
|
735
770
|
? await this.find(queryObj)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@positivegrid/pg-mongoose-schema",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.7.0",
|
|
4
4
|
"description": "Positive Grid mongoose schema",
|
|
5
5
|
"author": "Ferrari Lee <shiyung@positivegrid.com>",
|
|
6
6
|
"homepage": "https://git.positivegrid.com:8443/backend/pg-mongoose-schema",
|