@positivegrid/pg-mongoose-schema 27.8.5 → 28.0.0-beta.3
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/dist/index.cjs +5161 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.mts +1288 -0
- package/dist/index.mjs +5128 -0
- package/package.json +52 -4
- package/index.js +0 -28
- package/models/banks.js +0 -42
- package/models/device.js +0 -51
- package/models/featuredList.js +0 -91
- package/models/hardware.js +0 -256
- package/models/homeConfig.js +0 -97
- package/models/oauth.js +0 -52
- package/models/partner.js +0 -265
- package/models/payment.js +0 -899
- package/models/pgConfig.js +0 -88
- package/models/preset.js +0 -845
- package/models/promotion.js +0 -590
- package/models/redeem.js +0 -26
- package/models/toneTheme.js +0 -78
- package/models/toneThemeFeaturedList.js +0 -49
- package/models/user.js +0 -639
- package/models/userTrack.js +0 -107
package/models/promotion.js
DELETED
|
@@ -1,590 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = (mongoose) => {
|
|
4
|
-
const Schema = mongoose.Schema
|
|
5
|
-
const ObjectId = Schema.Types.ObjectId
|
|
6
|
-
const _ = require('lodash')
|
|
7
|
-
const debug = require('debug')('model:promotion')
|
|
8
|
-
|
|
9
|
-
// Support license campaign types
|
|
10
|
-
const CAMPAIGN_TYPE = [
|
|
11
|
-
'free_upgrade'
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* To make this collection fulfill any kinds of promotion events.
|
|
16
|
-
* We just put a type & detail, so it could be as flexible as possible.
|
|
17
|
-
* In our first sample, FX license upgrade, we'll use "free_upgrade" as type
|
|
18
|
-
* and detail would be "from" & "to".
|
|
19
|
-
*/
|
|
20
|
-
const LicenseCampaignMetaSchema = new Schema({
|
|
21
|
-
campaign_type: { type: String, enum: CAMPAIGN_TYPE, required: true },
|
|
22
|
-
campaign_detail: { type: Schema.Types.Mixed, required: true },
|
|
23
|
-
status: { type: Number, default: 1, required: true },
|
|
24
|
-
start_date: { type: Date, default: null },
|
|
25
|
-
end_date: { type: Date, default: null },
|
|
26
|
-
created_on: { type: Date, default: Date.now }
|
|
27
|
-
}, { collection: 'license_campaign_meta' })
|
|
28
|
-
|
|
29
|
-
const LicenseCampaignRecordSchema = new Schema({
|
|
30
|
-
user_id: { type: ObjectId, ref: 'auth_user', required: true },
|
|
31
|
-
campaign_event_id: { type: ObjectId, ref: 'license_campaign_meta', required: true },
|
|
32
|
-
status: { type: Number, default: 1, required: true },
|
|
33
|
-
created_on: { type: Date, default: Date.now, required: true }
|
|
34
|
-
}, { collection: 'license_campaign_record' })
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* News announcement system will be used on our app.
|
|
38
|
-
* spec: https://docs.google.com/document/d/1nvcqzKCiEtZY3Vt7laC7BENzk6_ylWuCJ9QNdHzqfeE/edit#heading=h.h63h324getn9
|
|
39
|
-
*/
|
|
40
|
-
const PublicAnnouncementSchema = new Schema({
|
|
41
|
-
title: { type: String, required: true },
|
|
42
|
-
content: { type: String, required: true },
|
|
43
|
-
type: { type: String, enum: ['announcement', 'freetrial'] },
|
|
44
|
-
country: [{ type: String }],
|
|
45
|
-
image: { type: String, default: null },
|
|
46
|
-
image_type: { type: String },
|
|
47
|
-
message_type: { type: String },
|
|
48
|
-
action_button: [{
|
|
49
|
-
type: { type: String, required: true },
|
|
50
|
-
text: { type: String, required: true },
|
|
51
|
-
// if type is free_trial the value would be object, with two special attributes:
|
|
52
|
-
// license_tier/days_after_activate/minutes_after_activate
|
|
53
|
-
// licenseTier: 1:elite/2:pro/3:std/4:lite
|
|
54
|
-
value: { type: Schema.Types.Mixed },
|
|
55
|
-
read: { type: Boolean, required: true }
|
|
56
|
-
}],
|
|
57
|
-
show_countdown: { type: Boolean, default: false, required: true },
|
|
58
|
-
// This field use to filter which product line the announcement will show.
|
|
59
|
-
// Follow the same name using on product name. e.g., bias/live/amp2/pedal
|
|
60
|
-
announce_for: [{ type: String, required: true }],
|
|
61
|
-
// This field use to filter by target audience device
|
|
62
|
-
// e.g, desktop/ios/hardware
|
|
63
|
-
target_audience_device: [{ type: String, required: true }],
|
|
64
|
-
device_os: { type: String },
|
|
65
|
-
device_list: [{ type: String }],
|
|
66
|
-
// If accouncement would be filtered by specific license users
|
|
67
|
-
// which would be the query condition to filter
|
|
68
|
-
// e.g., demo/lite/std/pro/elite
|
|
69
|
-
announce_license_tier: [{ type: String, required: true }],
|
|
70
|
-
announce_mobile_iap: [{ type: String, required: true }],
|
|
71
|
-
user_list_num: { type: Number, default: 0 },
|
|
72
|
-
user_list_status: { type: Number, default: 0 }, // 0:no/1:process/2:done
|
|
73
|
-
user_list_failure: { type: Number, default: 0 },
|
|
74
|
-
user_list_log: { type: String, default: null },
|
|
75
|
-
user_list_filename: { type: String, default: null },
|
|
76
|
-
start_time: { type: Date, default: null },
|
|
77
|
-
end_time: { type: Date, default: null },
|
|
78
|
-
locale: { type: String, required: true }, // Follow lang + country code: http://www.lingoes.net/en/translator/langcode.htm
|
|
79
|
-
order: { type: Number, default: 1 },
|
|
80
|
-
created_on: { type: Date, default: Date.now, required: true }
|
|
81
|
-
}, { collection: 'public_announcement' })
|
|
82
|
-
|
|
83
|
-
PublicAnnouncementSchema.static({
|
|
84
|
-
/**
|
|
85
|
-
* @param pname {string|array} - Product name used to filter on announce_for field.
|
|
86
|
-
**/
|
|
87
|
-
getAvailableAnnouncement: async function (params) {
|
|
88
|
-
try {
|
|
89
|
-
const nowTime = new Date()
|
|
90
|
-
const defaultQuery = {
|
|
91
|
-
'$and': [
|
|
92
|
-
{ '$or': [{ 'start_time': null }, { 'start_time': { '$lt': nowTime } }] },
|
|
93
|
-
{ '$or': [{ 'end_time': null }, { 'end_time': { '$gt': nowTime } }] },
|
|
94
|
-
]
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!_.isUndefined(params)) {
|
|
98
|
-
debug('getAvailableAnnouncement:querystring %o', params)
|
|
99
|
-
const {
|
|
100
|
-
pname,
|
|
101
|
-
locale,
|
|
102
|
-
ta_device,
|
|
103
|
-
country,
|
|
104
|
-
device_list,
|
|
105
|
-
device_os
|
|
106
|
-
} = params
|
|
107
|
-
if (!_.isUndefined(pname) && _.isString(pname)) {
|
|
108
|
-
defaultQuery['$and'].push({
|
|
109
|
-
announce_for: { '$in': _.concat([pname], 'all') }
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (!_.isUndefined(locale) && _.isString(locale)) {
|
|
114
|
-
defaultQuery['$and'].push({
|
|
115
|
-
'locale': locale
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!_.isUndefined(ta_device) && _.isString(ta_device)) {
|
|
120
|
-
defaultQuery['$and'].push({
|
|
121
|
-
'target_audience_device': { '$in': _.concat(ta_device.split(','), 'all') }
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (!_.isUndefined(country) && _.isString(country)) {
|
|
126
|
-
defaultQuery['$and'].push({
|
|
127
|
-
'$or': [
|
|
128
|
-
{ 'country': { '$all': country.split(',') } },
|
|
129
|
-
{ 'country': { '$in': ['all'] } }
|
|
130
|
-
]
|
|
131
|
-
})
|
|
132
|
-
} else {
|
|
133
|
-
defaultQuery['$and'].push({
|
|
134
|
-
'$or': [{
|
|
135
|
-
'country': { '$in': ['all'] }
|
|
136
|
-
}, {
|
|
137
|
-
'country': { '$exists': false }
|
|
138
|
-
}]
|
|
139
|
-
})
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!_.isUndefined(device_list)) {
|
|
143
|
-
if (_.isString(device_list) && !_.isEmpty(device_list)) {
|
|
144
|
-
const tmpDeviceList = device_list.split(',')
|
|
145
|
-
let deviceList = []
|
|
146
|
-
const allTypeSet = new Set()
|
|
147
|
-
const uniqueProductLineSet = new Set()
|
|
148
|
-
tmpDeviceList.forEach(deviceItem => {
|
|
149
|
-
const optionItem = deviceItem.split('_')
|
|
150
|
-
uniqueProductLineSet.add(optionItem[0])
|
|
151
|
-
if (optionItem.length === 2 && optionItem[1] === 'all') {
|
|
152
|
-
allTypeSet.add(optionItem[0])
|
|
153
|
-
} else {
|
|
154
|
-
deviceList.push(deviceItem)
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
if (allTypeSet.size > 0) {
|
|
158
|
-
allTypeSet.forEach(item => {
|
|
159
|
-
deviceList.push(new RegExp(`^${item}_`))
|
|
160
|
-
})
|
|
161
|
-
}
|
|
162
|
-
if (uniqueProductLineSet.size > 0) {
|
|
163
|
-
uniqueProductLineSet.forEach(item => {
|
|
164
|
-
deviceList.push(`${item}_all`)
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
defaultQuery['$and'].push({
|
|
168
|
-
'device_list': { $in: deviceList }
|
|
169
|
-
})
|
|
170
|
-
} else {
|
|
171
|
-
defaultQuery['$and'].push({
|
|
172
|
-
'device_list': { $in: ['none'] }
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (!_.isUndefined(device_os) && _.isString(device_os)) {
|
|
178
|
-
defaultQuery['$and'].push({
|
|
179
|
-
'$or': [{
|
|
180
|
-
'device_os': 'all'
|
|
181
|
-
}, {
|
|
182
|
-
'device_os': device_os
|
|
183
|
-
}]
|
|
184
|
-
})
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let ret
|
|
189
|
-
// Free trial PA only need to consider within query pass the auth
|
|
190
|
-
if (!_.has(params, 'email') || (_.has(params, 'email') && _.isUndefined(params.email))) {
|
|
191
|
-
defaultQuery['$and'].push({ 'user_list_num': 0 })
|
|
192
|
-
defaultQuery['$and'].push({ 'action_button': { '$elemMatch': { 'type': { '$ne': 'free_trial'} } } })
|
|
193
|
-
|
|
194
|
-
ret = await this.find(defaultQuery).lean().exec()
|
|
195
|
-
} else {
|
|
196
|
-
const noUserQuery = _.cloneDeep(defaultQuery)
|
|
197
|
-
noUserQuery['$and'].push({ 'user_list_num': 0 })
|
|
198
|
-
const hasUserQuery = _.cloneDeep(defaultQuery)
|
|
199
|
-
hasUserQuery['$and'].push({'user_list_num': {$gt: 0}})
|
|
200
|
-
debug('getAvailablePA:%j:%j', noUserQuery, hasUserQuery)
|
|
201
|
-
|
|
202
|
-
let [noUserData, hasUserData] = await Promise.all([
|
|
203
|
-
this.aggregate([
|
|
204
|
-
{
|
|
205
|
-
'$match': noUserQuery
|
|
206
|
-
}
|
|
207
|
-
]).exec(),
|
|
208
|
-
this.aggregate([
|
|
209
|
-
{
|
|
210
|
-
'$match': hasUserQuery
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
'$lookup': {
|
|
214
|
-
'from': 'public_announcement_userlist',
|
|
215
|
-
'localField': '_id',
|
|
216
|
-
'foreignField': 'pa_id',
|
|
217
|
-
'as': 'paUserList'
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
'$unwind': '$paUserList'
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
'$match': {
|
|
225
|
-
'paUserList.email': String(params.email).toLowerCase(),
|
|
226
|
-
'paUserList.status': 1
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
]).exec()
|
|
230
|
-
])
|
|
231
|
-
ret = _.concat(noUserData, hasUserData)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
debug('INFO:getAvailableAnnouncement %j:%j', ret, defaultQuery)
|
|
235
|
-
return _.orderBy(ret, ['order', 'start_time'], ['desc', 'asc'])
|
|
236
|
-
} catch (err) {
|
|
237
|
-
debug('ERR:getAvailableAnnouncement %j', err)
|
|
238
|
-
throw err
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
const PublicAnnouncementFreeTrialSchema = new Schema({
|
|
244
|
-
pa_id: { type: ObjectId, ref: 'PublicAnnouncement', required: true },
|
|
245
|
-
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
246
|
-
product_id: { type: ObjectId, ref: 'Product', default: null },
|
|
247
|
-
expansion_id: { type: ObjectId, ref: 'Product', default: null },
|
|
248
|
-
status: { type: Number, default: 1 },
|
|
249
|
-
expire_on: { type: Date, required: true },
|
|
250
|
-
created_on: { type: Date, default: Date.now }
|
|
251
|
-
}, { collection: 'public_announcement_free_trial'})
|
|
252
|
-
PublicAnnouncementFreeTrialSchema.index({ pa_id: 1, user_id: 1, product_id: 1, expansion_id: 1 }, { unique: true })
|
|
253
|
-
|
|
254
|
-
PublicAnnouncementFreeTrialSchema.static({
|
|
255
|
-
getCurrentActiveFreeTrial: async function (params) {
|
|
256
|
-
try {
|
|
257
|
-
const { userId } = params
|
|
258
|
-
if (!userId) {
|
|
259
|
-
throw new Error('Missing userId')
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const nowTime = new Date()
|
|
263
|
-
const ret = await this.aggregate([
|
|
264
|
-
{
|
|
265
|
-
'$match': {
|
|
266
|
-
user_id: mongoose.Types.ObjectId(userId)
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
$lookup: {
|
|
271
|
-
from: 'public_announcement',
|
|
272
|
-
localField: 'pa_id',
|
|
273
|
-
foreignField: '_id',
|
|
274
|
-
as: 'pa'
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
$unwind: {
|
|
279
|
-
path: '$pa',
|
|
280
|
-
preserveNullAndEmptyArrays: false
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
$match: {
|
|
285
|
-
$and: [
|
|
286
|
-
{ '$or': [{ 'pa.start_time': null }, { 'pa.start_time': { '$lt': nowTime } }] },
|
|
287
|
-
{ '$or': [{ 'pa.end_time': null }, { 'pa.end_time': { '$gt': nowTime } }] },
|
|
288
|
-
]
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
]).exec()
|
|
292
|
-
|
|
293
|
-
debug('INFO:getCurrentActiveFreeTrial:%j:%j', ret, params)
|
|
294
|
-
return ret
|
|
295
|
-
} catch (err) {
|
|
296
|
-
debug('ERR:getAvailableFreeTrial %o', err)
|
|
297
|
-
throw err
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
const PublicAnnouncementUserListSchema = new Schema({
|
|
303
|
-
pa_id: { type: ObjectId, ref: 'PublicAnnouncement', required: true },
|
|
304
|
-
email: { type: String, required: true },
|
|
305
|
-
user_id: { type: ObjectId, ref: 'User' },
|
|
306
|
-
status: { type: Number, default: 1, required: true }, // 1:active/2:inactive/3:used
|
|
307
|
-
created_on: { type: Date, default: Date.now, required: true }
|
|
308
|
-
}, { collection: 'public_announcement_userlist' })
|
|
309
|
-
|
|
310
|
-
PublicAnnouncementUserListSchema.static({
|
|
311
|
-
getAvailableAnnouncementByEmail: async function (email) {
|
|
312
|
-
try {
|
|
313
|
-
const ret = this.aggregate([
|
|
314
|
-
{
|
|
315
|
-
'$match': {
|
|
316
|
-
'email': String(email).toLowerCase(),
|
|
317
|
-
'status': 1
|
|
318
|
-
}
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
'$lookup': {
|
|
322
|
-
'from': 'public_announcement',
|
|
323
|
-
'localField': 'pa_id',
|
|
324
|
-
'foreignField': '_id',
|
|
325
|
-
'as': 'pa'
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
'$match': {
|
|
330
|
-
'$and': [
|
|
331
|
-
{ '$or': [{ '$pa.start_time': null }, { '$pa.start_time': { '$lt': nowTime } }] },
|
|
332
|
-
{ '$or': [{ '$pa.end_time': null }, { '$pa.end_time': { '$gt': nowTime } }] },
|
|
333
|
-
{ '$pa.user_list_num': { $gt: 0 } }
|
|
334
|
-
]
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
]).exec()
|
|
338
|
-
debug('INFO:getAvailableAnnouncementByEmail:%o', ret)
|
|
339
|
-
return ret
|
|
340
|
-
} catch (err) {
|
|
341
|
-
debug('ERR:getAnnouncementFromUserList:%o', err)
|
|
342
|
-
throw err
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
const PublicAnnouncementUserListLog = new Schema({
|
|
348
|
-
pa_id: { type: ObjectId, ref: 'PublicAnnouncement', required: true },
|
|
349
|
-
message: { type: Schema.Types.Mixed }
|
|
350
|
-
}, { collection: 'public_announcement_userlist_log' })
|
|
351
|
-
|
|
352
|
-
const IasBuyOptionSchema = new Schema({
|
|
353
|
-
type: { type: String, required: true },
|
|
354
|
-
sku: { type: String, required: true },
|
|
355
|
-
description: { type: String, required: true },
|
|
356
|
-
cta_name: { type: String, required: true },
|
|
357
|
-
created_on: { type: Date, default: Date.now, required: true },
|
|
358
|
-
locale: { type: String, required: true }
|
|
359
|
-
}, { collection: 'ias_buy_option' })
|
|
360
|
-
|
|
361
|
-
const IasStorePageMetaSchema = new Schema({
|
|
362
|
-
product: { type: String, required: true },
|
|
363
|
-
expansion: { type: Boolean, default: false },
|
|
364
|
-
license: { type: String, required: true },
|
|
365
|
-
buy_option: [{ type: ObjectId, ref: 'IasBuyOption', required: true }],
|
|
366
|
-
created_on: { type: Date, default: Date.now, required: true },
|
|
367
|
-
promotion_target_audiance: { type: String, required: true },
|
|
368
|
-
promotion_discount: { type: String, required: true },
|
|
369
|
-
product_description: { type: String, required: true },
|
|
370
|
-
quote_image: { type: String, required: true },
|
|
371
|
-
locale: { type: String, required: true },
|
|
372
|
-
cta_image: { type: String },
|
|
373
|
-
cta_button_text: { type: String },
|
|
374
|
-
cta_button_show_svg: { type: Boolean },
|
|
375
|
-
cta_button_action_url: { type: String }
|
|
376
|
-
}, { collection: 'ias_store_page_meta' })
|
|
377
|
-
|
|
378
|
-
const IasPromotionSchema = new Schema({
|
|
379
|
-
start_time: { type: Date, required: true },
|
|
380
|
-
end_time: { type: Date, required: true },
|
|
381
|
-
quote_image: { type: String, required: true },
|
|
382
|
-
created_on: { type: Date, default: Date.now, required: true }
|
|
383
|
-
}, { collection: 'ias_promotion' })
|
|
384
|
-
|
|
385
|
-
const SpecialOfferSchema = new Schema({
|
|
386
|
-
title: { type: String, required: true },
|
|
387
|
-
content: { type: String, required: true },
|
|
388
|
-
image: { type: String, default: null },
|
|
389
|
-
action_button: [{
|
|
390
|
-
type: { type: String, required: true },
|
|
391
|
-
text: { type: String, required: true },
|
|
392
|
-
value: { type: Schema.Types.Mixed },
|
|
393
|
-
read: { type: Boolean, required: true }
|
|
394
|
-
}],
|
|
395
|
-
announce_for: [{ type: String, required: true }],
|
|
396
|
-
target_audience_device: [{ type: String, required: true }],
|
|
397
|
-
start_time: { type: Date, default: null },
|
|
398
|
-
end_time: { type: Date, default: null },
|
|
399
|
-
created_on: { type: Date, default: Date.now, required: true },
|
|
400
|
-
locale: { type: String, required: true }
|
|
401
|
-
}, { collection: 'special_offer' })
|
|
402
|
-
|
|
403
|
-
const PromotionSchema = new Schema({
|
|
404
|
-
name: { type: String, required: true },
|
|
405
|
-
start_date: { type: Date, required: true },
|
|
406
|
-
end_date: { type: Date, required: true },
|
|
407
|
-
items: [{
|
|
408
|
-
sku: { type: String, required: true },
|
|
409
|
-
sale_price: { type: Number, required: true },
|
|
410
|
-
price: { type: Number, required: true },
|
|
411
|
-
name: { type: String, required: true }
|
|
412
|
-
}]
|
|
413
|
-
}, { collection: 'promotion' })
|
|
414
|
-
|
|
415
|
-
// Use for campaign event which will collect user information
|
|
416
|
-
const CampaignUserInfoSchema = new Schema({
|
|
417
|
-
campaign: { type: String, required: true },
|
|
418
|
-
email: { type: String, required: true },
|
|
419
|
-
name: { type: String },
|
|
420
|
-
redeem: { type: String },
|
|
421
|
-
metadata: { type: Schema.Types.Mixed },
|
|
422
|
-
created_on: { type: Date, default: Date.now }
|
|
423
|
-
}, { collection: 'campaign_user_info' })
|
|
424
|
-
CampaignUserInfoSchema.index({ campaign: 1 })
|
|
425
|
-
CampaignUserInfoSchema.index({ campaign: 1, email: 1 }, { unique: true })
|
|
426
|
-
CampaignUserInfoSchema.index({ campaign: 1, email: 1, redeem: 1 })
|
|
427
|
-
|
|
428
|
-
const CouponPromotionSchema = new Schema({
|
|
429
|
-
email: { type: String, required: true },
|
|
430
|
-
code: { type: String, required: true },
|
|
431
|
-
referral: { type: String },
|
|
432
|
-
event: { type: String },
|
|
433
|
-
type: { type: String },
|
|
434
|
-
metadata: { type: Schema.Types.Mixed },
|
|
435
|
-
status: { type: Number, default: 1, required: true },
|
|
436
|
-
created_on: { type: Date, default: Date.now, required: true }
|
|
437
|
-
}, { collection: 'coupon_promotion' })
|
|
438
|
-
CouponPromotionSchema.index({ email: 1, event: 1 })
|
|
439
|
-
CouponPromotionSchema.index({ email: 1, event: 1, referral: 1 }, { unique: true })
|
|
440
|
-
|
|
441
|
-
const TierSalesMetaSchema = new Schema({
|
|
442
|
-
campaign_key: { type: String, required: true },
|
|
443
|
-
current_tier_sales_rule: {
|
|
444
|
-
type: ObjectId,
|
|
445
|
-
ref: 'TierSalesRules',
|
|
446
|
-
},
|
|
447
|
-
current_tier_startdate: { type: Date, default: null },
|
|
448
|
-
process_log: [
|
|
449
|
-
{
|
|
450
|
-
from_tier_id: {
|
|
451
|
-
type: ObjectId,
|
|
452
|
-
ref: 'TierSalesRules',
|
|
453
|
-
required: true,
|
|
454
|
-
},
|
|
455
|
-
to_tier_id: {
|
|
456
|
-
type: ObjectId,
|
|
457
|
-
ref: 'TierSalesRules',
|
|
458
|
-
required: true,
|
|
459
|
-
},
|
|
460
|
-
updated_on: { type: Date, required: true },
|
|
461
|
-
},
|
|
462
|
-
],
|
|
463
|
-
status: { type: Number, default: 1 }, // 1:start/2:end/3:draft
|
|
464
|
-
updated_on: { type: Date, default: Date.now }
|
|
465
|
-
}, { collection: 'tier_sales_meta' })
|
|
466
|
-
|
|
467
|
-
const TierSalesRulesSchema = new Schema({
|
|
468
|
-
campaign_key: { type: String, required: true },
|
|
469
|
-
tier_level: { type: Number, default: 1, required: true },
|
|
470
|
-
tier_type: { type: Number, default: 0 }, //0:no/1:reach_goal/2:not_reach
|
|
471
|
-
pre_rule_id: {
|
|
472
|
-
type: ObjectId,
|
|
473
|
-
ref: 'TierSalesRules',
|
|
474
|
-
},
|
|
475
|
-
price: { type: Number, required: true },
|
|
476
|
-
ta_sku: { type: String, required: true },
|
|
477
|
-
next_sku: { type: String, default: null },
|
|
478
|
-
goal: [
|
|
479
|
-
{
|
|
480
|
-
type: { type: String }, // sold/time
|
|
481
|
-
value: { type: Number }, // if the type is 'sold' then number, if 'time' then minute
|
|
482
|
-
},
|
|
483
|
-
],
|
|
484
|
-
force_switch_tier: { type: Date, default: null },
|
|
485
|
-
is_final_tier: { type: Boolean, default: false },
|
|
486
|
-
status: { type: Number, default: 1 },
|
|
487
|
-
created_on: { type: Date, default: Date.now }
|
|
488
|
-
}, { collection: 'tier_sales_rules' })
|
|
489
|
-
|
|
490
|
-
const GearTrialMetaSchema = new Schema({
|
|
491
|
-
title: { type: String, required: true },
|
|
492
|
-
// This field use to filter which product line the announcement will show.
|
|
493
|
-
// Follow the same name using on product name. e.g., amp2/fx2
|
|
494
|
-
announce_for: [{ type: String, required: true }],
|
|
495
|
-
// This field use to filter by target audience device
|
|
496
|
-
// e.g, desktop/ios/hardware
|
|
497
|
-
target_audience_device: [{ type: String, required: true }],
|
|
498
|
-
locale: { type: String, required: true }, // Follow lang + country code: http://www.lingoes.net/en/translator/langcode.htm
|
|
499
|
-
target_product_sku: [{ type: String, required: true }],
|
|
500
|
-
expires: { type: Number, required: true },
|
|
501
|
-
status: { type: Number, default: 1, required: true }, //inactive: 0/active: 1
|
|
502
|
-
created_on: { type: Date, default: Date.now, required: true }
|
|
503
|
-
}, { collection: 'gear_trial_meta' })
|
|
504
|
-
GearTrialMetaSchema.index({ status: 1 })
|
|
505
|
-
|
|
506
|
-
const GearTrialRecordSchema = new Schema({
|
|
507
|
-
gear_trial_id: { type: ObjectId, ref: 'gear_trial_meta', required: true },
|
|
508
|
-
user_id: { type: ObjectId, ref: 'auth_user', required: true },
|
|
509
|
-
expire_on: { type: Date, required: true },
|
|
510
|
-
created_on: { type: Date, default: Date.now, required: true }
|
|
511
|
-
}, { collection: 'gear_trial_record' })
|
|
512
|
-
GearTrialRecordSchema.index({ gear_trial_id: 1, user_id: 1 })
|
|
513
|
-
GearTrialRecordSchema.index({ user_id: 1, expire_on: 1 })
|
|
514
|
-
|
|
515
|
-
const YotpoLoyaltySchema = new Schema({
|
|
516
|
-
user_id: { type: ObjectId, ref: 'auth_user', required: true },
|
|
517
|
-
main_region: { type: String, required: true },
|
|
518
|
-
active_regions: [{
|
|
519
|
-
code: { type: String, required: true },
|
|
520
|
-
points_balance: { type: Number, default: 0, required: true },
|
|
521
|
-
points_earned: { type: Number, default: 0, required: true },
|
|
522
|
-
}],
|
|
523
|
-
history: [{
|
|
524
|
-
created_at: { type: String, required: true },
|
|
525
|
-
date: { type: String, required: true },
|
|
526
|
-
completed_on: { type: String, default: null },
|
|
527
|
-
action: { type: String, default: null },
|
|
528
|
-
points: { type: Number, default: 0 },
|
|
529
|
-
status: { type: String, default: null },
|
|
530
|
-
action_name: { type: String, default: null },
|
|
531
|
-
order_ids: [{ type: String }]
|
|
532
|
-
}],
|
|
533
|
-
created_on: { type: Date, default: Date.now, required: true },
|
|
534
|
-
updated_on: { type: Date, default: Date.now, required: true }
|
|
535
|
-
}, { collection: 'auth_yotpo_loyalty' })
|
|
536
|
-
YotpoLoyaltySchema.index({ user_id: 1 }, { unique: true })
|
|
537
|
-
YotpoLoyaltySchema.index({ user_id: 1, main_region: 1, 'active_regions.code': 1 })
|
|
538
|
-
|
|
539
|
-
const YotpoLoyaltyBackupSchema = new Schema({
|
|
540
|
-
email: { type: String, required: true },
|
|
541
|
-
store_code: { type: String, required: true },
|
|
542
|
-
status: { type: Number, default: 1, required: true }, // 1:wait for apply/2:applied/3:deleted
|
|
543
|
-
created_on: { type: Date, default: Date.now, required: true },
|
|
544
|
-
}, { collection: 'yotpo_loyalty_backup' })
|
|
545
|
-
YotpoLoyaltyBackupSchema.index({ email: 1, store_code: 1 }, { unique: true })
|
|
546
|
-
|
|
547
|
-
const FreeTrialSchema = new Schema({
|
|
548
|
-
campaign_name: { type: String, required: true },
|
|
549
|
-
campaign_code: { type: String, required: true },
|
|
550
|
-
content: { type: String, default: null },
|
|
551
|
-
products: [{ type: ObjectId, ref: 'Product', required: true }],
|
|
552
|
-
status: { type: Number, default: 1, required: true }, // 0:draft/1:actived/2:deactivated
|
|
553
|
-
start_time: { type: Date, required: true },
|
|
554
|
-
end_time: { type: Date, required: true },
|
|
555
|
-
trial_days: { type: Number, default: 0 },
|
|
556
|
-
not_allow_same_product: { type: Boolean, default: false },
|
|
557
|
-
created_by: { type: String, default: null },
|
|
558
|
-
terminate: {
|
|
559
|
-
reason: { type: String },
|
|
560
|
-
user: { type: String },
|
|
561
|
-
time: { type: Date },
|
|
562
|
-
},
|
|
563
|
-
metadata: { type: Schema.Types.Mixed, default: null },
|
|
564
|
-
created_on: { type: Date, default: Date.now, required: true },
|
|
565
|
-
updated_on: { type: Date, default: Date.now, required: true }
|
|
566
|
-
}, { collection: 'free_trial_campaign' })
|
|
567
|
-
FreeTrialSchema.index({ campaign_code: 1 }, { unique: true })
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
mongoose.model('LicenseCampaignMeta', LicenseCampaignMetaSchema)
|
|
571
|
-
mongoose.model('LicenseCampaignRecord', LicenseCampaignRecordSchema)
|
|
572
|
-
mongoose.model('PublicAnnouncement', PublicAnnouncementSchema)
|
|
573
|
-
mongoose.model('PublicAnnouncementUserList', PublicAnnouncementUserListSchema)
|
|
574
|
-
mongoose.model('PublicAnnouncementUserListLog', PublicAnnouncementUserListLog)
|
|
575
|
-
mongoose.model('PublicAnnouncementFreeTrial', PublicAnnouncementFreeTrialSchema)
|
|
576
|
-
mongoose.model('IasBuyOption', IasBuyOptionSchema)
|
|
577
|
-
mongoose.model('IasStorePageMeta', IasStorePageMetaSchema)
|
|
578
|
-
mongoose.model('IasPromotion', IasPromotionSchema)
|
|
579
|
-
mongoose.model('SpecialOffer', SpecialOfferSchema)
|
|
580
|
-
mongoose.model('Promotion', PromotionSchema)
|
|
581
|
-
mongoose.model('CampaignUserInfo', CampaignUserInfoSchema)
|
|
582
|
-
mongoose.model('CouponPromotion', CouponPromotionSchema)
|
|
583
|
-
mongoose.model('TierSalesMeta', TierSalesMetaSchema)
|
|
584
|
-
mongoose.model('TierSalesRules', TierSalesRulesSchema)
|
|
585
|
-
mongoose.model('GearTrialMeta', GearTrialMetaSchema)
|
|
586
|
-
mongoose.model('GearTrialRecord', GearTrialRecordSchema)
|
|
587
|
-
mongoose.model('YotpoLoyalty', YotpoLoyaltySchema)
|
|
588
|
-
mongoose.model('YotpoLoyaltyBackup', YotpoLoyaltyBackupSchema)
|
|
589
|
-
mongoose.model('FreeTrial', FreeTrialSchema)
|
|
590
|
-
}
|
package/models/redeem.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = function (mongoose) {
|
|
4
|
-
const Schema = mongoose.Schema
|
|
5
|
-
const ObjectId = Schema.Types.ObjectId
|
|
6
|
-
|
|
7
|
-
const RedeemCodeSchema = new Schema({
|
|
8
|
-
code: { type: String, required: true },
|
|
9
|
-
product_id: { type: ObjectId, ref: 'Product', default: null },
|
|
10
|
-
bundle_id: { type: ObjectId, ref: 'Bundle', default: null },
|
|
11
|
-
user_id: { type: ObjectId, ref: 'User', default: null },
|
|
12
|
-
status: { type: Number, default: 1, required: true }, //1:active/2:used/3:invalid/4:refunded
|
|
13
|
-
expire_on: { type: Date, default: null },
|
|
14
|
-
trial_due_date: { type: Date, default: null },
|
|
15
|
-
tracker: { type: String, required: true },
|
|
16
|
-
metadata: { type: Schema.Types.Mixed },
|
|
17
|
-
created_on: { type: Date, default: Date.now },
|
|
18
|
-
updated_on: { type: Date, default: Date.now }
|
|
19
|
-
}, { collection: 'pg_redeem_code' })
|
|
20
|
-
RedeemCodeSchema.index({ code: 1, status: 1 }, { unique: true })
|
|
21
|
-
RedeemCodeSchema.index({ code: 1, product_id: 1, status: 1 })
|
|
22
|
-
RedeemCodeSchema.index({ code: 1, bundle_id: 1, status: 1 })
|
|
23
|
-
RedeemCodeSchema.index({ tracker: 1 })
|
|
24
|
-
|
|
25
|
-
mongoose.model('RedeemCode', RedeemCodeSchema)
|
|
26
|
-
}
|
package/models/toneTheme.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const mongooseLeanVirtuals = require('mongoose-lean-virtuals')
|
|
4
|
-
|
|
5
|
-
module.exports = function (mongoose) {
|
|
6
|
-
const Schema = mongoose.Schema
|
|
7
|
-
|
|
8
|
-
const ToneThemeSchema = new Schema({
|
|
9
|
-
title: {
|
|
10
|
-
type: String,
|
|
11
|
-
required: true,
|
|
12
|
-
trim: true
|
|
13
|
-
},
|
|
14
|
-
description: {
|
|
15
|
-
type: String,
|
|
16
|
-
trim: true,
|
|
17
|
-
default: null
|
|
18
|
-
},
|
|
19
|
-
cover_image_url: {
|
|
20
|
-
type: String,
|
|
21
|
-
default: null
|
|
22
|
-
},
|
|
23
|
-
thumb_url: {
|
|
24
|
-
type: String,
|
|
25
|
-
default: null
|
|
26
|
-
},
|
|
27
|
-
order: {
|
|
28
|
-
type: Number,
|
|
29
|
-
default: 0
|
|
30
|
-
},
|
|
31
|
-
is_shown: {
|
|
32
|
-
type: Boolean,
|
|
33
|
-
default: false
|
|
34
|
-
},
|
|
35
|
-
list_for: {
|
|
36
|
-
type: String,
|
|
37
|
-
required: true
|
|
38
|
-
},
|
|
39
|
-
category: {
|
|
40
|
-
type: String,
|
|
41
|
-
default: null
|
|
42
|
-
},
|
|
43
|
-
tags: [{
|
|
44
|
-
type: String
|
|
45
|
-
}],
|
|
46
|
-
created_on: {
|
|
47
|
-
type: Date,
|
|
48
|
-
default: Date.now
|
|
49
|
-
},
|
|
50
|
-
updated_on: {
|
|
51
|
-
type: Date,
|
|
52
|
-
default: Date.now
|
|
53
|
-
}
|
|
54
|
-
}, {
|
|
55
|
-
collection: 'tone_theme',
|
|
56
|
-
toJSON: { virtuals: true },
|
|
57
|
-
toObject: { virtuals: true }
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
// 索引
|
|
61
|
-
ToneThemeSchema.index({
|
|
62
|
-
list_for: 1,
|
|
63
|
-
is_shown: 1,
|
|
64
|
-
order: 1,
|
|
65
|
-
created_on: -1
|
|
66
|
-
})
|
|
67
|
-
ToneThemeSchema.index({ category: 1 })
|
|
68
|
-
ToneThemeSchema.index({ tags: 1 })
|
|
69
|
-
|
|
70
|
-
ToneThemeSchema.plugin(mongooseLeanVirtuals)
|
|
71
|
-
|
|
72
|
-
ToneThemeSchema.virtual('id')
|
|
73
|
-
.get(function () {
|
|
74
|
-
return this._id.toHexString()
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
mongoose.model('ToneTheme', ToneThemeSchema)
|
|
78
|
-
}
|