@positivegrid/pg-mongoose-schema 27.3.3 → 27.4.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.
@@ -143,22 +143,28 @@ module.exports = function (mongoose) {
143
143
  const tmpDeviceList = device_list.split(',')
144
144
  let deviceList = []
145
145
  const allTypeSet = new Set()
146
+ const uniqueProductLineSet = new Set()
146
147
  tmpDeviceList.forEach(deviceItem => {
147
148
  const optionItem = deviceItem.split('_')
149
+ uniqueProductLineSet.add(optionItem[0])
148
150
  if (optionItem.length === 2 && optionItem[1] === 'all') {
149
151
  allTypeSet.add(optionItem[0])
150
152
  } else {
151
153
  deviceList.push(deviceItem)
152
154
  }
153
155
  })
154
- let allTypeRegex = []
155
156
  if (allTypeSet.size > 0) {
156
157
  allTypeSet.forEach(item => {
157
- allTypeRegex.push(new RegExp(`^${item}_`))
158
+ deviceList.push(new RegExp(`^${item}_`))
159
+ })
160
+ }
161
+ if (uniqueProductLineSet.size > 0) {
162
+ uniqueProductLineSet.forEach(item => {
163
+ deviceList.push(`${item}_all`)
158
164
  })
159
165
  }
160
166
  defaultQuery['$and'].push({
161
- 'device_list': { $in: deviceList.concat(allTypeRegex) }
167
+ 'device_list': { $in: deviceList }
162
168
  })
163
169
  } else {
164
170
  defaultQuery['$and'].push({
@@ -505,6 +511,28 @@ module.exports = function (mongoose) {
505
511
  GearTrialRecordSchema.index({ gear_trial_id: 1, user_id: 1 })
506
512
  GearTrialRecordSchema.index({ user_id: 1, expire_on: 1 })
507
513
 
514
+ const YotpoLoyaltySchema = new Schema({
515
+ user_id: { type: ObjectId, ref: 'auth_user', required: true },
516
+ main_region: { type: String, required: true },
517
+ active_regions: [{
518
+ code: { type: String, required: true },
519
+ points_balance: { type: Number, default: 0, required: true },
520
+ points_earned: { type: Number, default: 0, required: true },
521
+ }],
522
+ created_on: { type: Date, default: Date.now, required: true },
523
+ updated_on: { type: Date, default: Date.now, required: true }
524
+ }, { collection: 'auth_yotpo_loyalty' })
525
+ YotpoLoyaltySchema.index({ user_id: 1 }, { unique: true })
526
+ YotpoLoyaltySchema.index({ user_id: 1, main_region: 1, 'active_regions.code': 1 })
527
+
528
+ const YotpoLoyaltyBackupSchema = new Schema({
529
+ email: { type: String, required: true },
530
+ store_code: { type: String, required: true },
531
+ status: { type: Number, default: 1, required: true }, // 1:wait for apply/2:applied/3:deleted
532
+ created_on: { type: Date, default: Date.now, required: true },
533
+ })
534
+ YotpoLoyaltyBackupSchema.index({ email: 1, store_code: 1 }, { unique: true })
535
+
508
536
  mongoose.model('LicenseCampaignMeta', LicenseCampaignMetaSchema)
509
537
  mongoose.model('LicenseCampaignRecord', LicenseCampaignRecordSchema)
510
538
  mongoose.model('PublicAnnouncement', PublicAnnouncementSchema)
@@ -522,4 +550,6 @@ module.exports = function (mongoose) {
522
550
  mongoose.model('TierSalesRules', TierSalesRulesSchema)
523
551
  mongoose.model('GearTrialMeta', GearTrialMetaSchema)
524
552
  mongoose.model('GearTrialRecord', GearTrialRecordSchema)
553
+ mongoose.model('YotpoLoyalty', YotpoLoyaltySchema)
554
+ mongoose.model('YotpoLoyaltyBackup', YotpoLoyaltyBackupSchema)
525
555
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@positivegrid/pg-mongoose-schema",
3
- "version": "27.3.3",
3
+ "version": "27.4.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",