@positivegrid/pg-mongoose-schema 27.6.2 → 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.
Files changed (2) hide show
  1. package/models/payment.js +31 -1
  2. package/package.json +1 -1
package/models/payment.js CHANGED
@@ -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', toJSON: { virtuals: true }, toObject: { virtuals: true } })
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 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@positivegrid/pg-mongoose-schema",
3
- "version": "27.6.2",
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",