@positivegrid/pg-mongoose-schema 27.8.5 → 28.0.0-beta.1
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.d.ts +5 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/models/banks.d.ts +3 -0
- package/dist/models/banks.js +33 -0
- package/dist/models/banks.js.map +1 -0
- package/dist/models/device.d.ts +3 -0
- package/dist/models/device.js +48 -0
- package/dist/models/device.js.map +1 -0
- package/dist/models/featuredList.d.ts +3 -0
- package/dist/models/featuredList.js +70 -0
- package/dist/models/featuredList.js.map +1 -0
- package/dist/models/hardware.d.ts +3 -0
- package/dist/models/hardware.js +213 -0
- package/dist/models/hardware.js.map +1 -0
- package/dist/models/homeConfig.d.ts +3 -0
- package/dist/models/homeConfig.js +38 -0
- package/dist/models/homeConfig.js.map +1 -0
- package/dist/models/oauth.d.ts +3 -0
- package/dist/models/oauth.js +48 -0
- package/dist/models/oauth.js.map +1 -0
- package/dist/models/partner.d.ts +3 -0
- package/dist/models/partner.js +165 -0
- package/dist/models/partner.js.map +1 -0
- package/dist/models/payment.d.ts +3 -0
- package/dist/models/payment.js +859 -0
- package/dist/models/payment.js.map +1 -0
- package/dist/models/pgConfig.d.ts +3 -0
- package/dist/models/pgConfig.js +64 -0
- package/dist/models/pgConfig.js.map +1 -0
- package/dist/models/preset.d.ts +3 -0
- package/dist/models/preset.js +802 -0
- package/dist/models/preset.js.map +1 -0
- package/dist/models/promotion.d.ts +3 -0
- package/dist/models/promotion.js +585 -0
- package/dist/models/promotion.js.map +1 -0
- package/dist/models/redeem.d.ts +3 -0
- package/dist/models/redeem.js +26 -0
- package/dist/models/redeem.js.map +1 -0
- package/dist/models/toneTheme.d.ts +3 -0
- package/dist/models/toneTheme.js +29 -0
- package/dist/models/toneTheme.js.map +1 -0
- package/dist/models/toneThemeFeaturedList.d.ts +3 -0
- package/dist/models/toneThemeFeaturedList.js +18 -0
- package/dist/models/toneThemeFeaturedList.js.map +1 -0
- package/dist/models/user.d.ts +3 -0
- package/dist/models/user.js +565 -0
- package/dist/models/user.js.map +1 -0
- package/dist/models/userTrack.d.ts +3 -0
- package/dist/models/userTrack.js +82 -0
- package/dist/models/userTrack.js.map +1 -0
- package/dist/types/banks.types.d.ts +25 -0
- package/dist/types/banks.types.js +3 -0
- package/dist/types/banks.types.js.map +1 -0
- package/dist/types/device.types.d.ts +41 -0
- package/dist/types/device.types.js +3 -0
- package/dist/types/device.types.js.map +1 -0
- package/dist/types/featuredList.types.d.ts +32 -0
- package/dist/types/featuredList.types.js +3 -0
- package/dist/types/featuredList.types.js.map +1 -0
- package/dist/types/hardware.types.d.ts +123 -0
- package/dist/types/hardware.types.js +3 -0
- package/dist/types/hardware.types.js.map +1 -0
- package/dist/types/homeConfig.types.d.ts +24 -0
- package/dist/types/homeConfig.types.js +3 -0
- package/dist/types/homeConfig.types.js.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.js +34 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/oauth.types.d.ts +38 -0
- package/dist/types/oauth.types.js +3 -0
- package/dist/types/oauth.types.js.map +1 -0
- package/dist/types/partner.types.d.ts +91 -0
- package/dist/types/partner.types.js +3 -0
- package/dist/types/partner.types.js.map +1 -0
- package/dist/types/payment.types.d.ts +304 -0
- package/dist/types/payment.types.js +3 -0
- package/dist/types/payment.types.js.map +1 -0
- package/dist/types/pgConfig.types.d.ts +35 -0
- package/dist/types/pgConfig.types.js +3 -0
- package/dist/types/pgConfig.types.js.map +1 -0
- package/dist/types/preset.types.d.ts +110 -0
- package/dist/types/preset.types.js +3 -0
- package/dist/types/preset.types.js.map +1 -0
- package/dist/types/promotion.types.d.ts +282 -0
- package/dist/types/promotion.types.js +3 -0
- package/dist/types/promotion.types.js.map +1 -0
- package/dist/types/redeem.types.d.ts +16 -0
- package/dist/types/redeem.types.js +3 -0
- package/dist/types/redeem.types.js.map +1 -0
- package/dist/types/toneTheme.types.d.ts +16 -0
- package/dist/types/toneTheme.types.js +3 -0
- package/dist/types/toneTheme.types.js.map +1 -0
- package/dist/types/toneThemeFeaturedList.types.d.ts +9 -0
- package/dist/types/toneThemeFeaturedList.types.js +3 -0
- package/dist/types/toneThemeFeaturedList.types.js.map +1 -0
- package/dist/types/user.types.d.ts +166 -0
- package/dist/types/user.types.js +6 -0
- package/dist/types/user.types.js.map +1 -0
- package/dist/types/userTrack.types.d.ts +39 -0
- package/dist/types/userTrack.types.js +12 -0
- package/dist/types/userTrack.types.js.map +1 -0
- package/package.json +38 -12
- 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/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const debug = require('debug')('model:init')
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* mongoose - mongoose instance
|
|
9
|
-
* type - {account}
|
|
10
|
-
*/
|
|
11
|
-
module.exports = function (mongoose, type) {
|
|
12
|
-
debug('Loading type: %s', type)
|
|
13
|
-
if (type === 'account') {
|
|
14
|
-
require(path.join(__dirname, '/models/user.js'))(mongoose)
|
|
15
|
-
require(path.join(__dirname, '/models/oauth.js'))(mongoose)
|
|
16
|
-
require(path.join(__dirname, '/models/partner.js'))(mongoose)
|
|
17
|
-
require(path.join(__dirname, '/models/payment.js'))(mongoose)
|
|
18
|
-
require(path.join(__dirname, '/models/hardware.js'))(mongoose)
|
|
19
|
-
} else if (type === 'hardware') {
|
|
20
|
-
require(path.join(__dirname, '/models/hardware.js'))(mongoose)
|
|
21
|
-
} else {
|
|
22
|
-
fs.readdirSync(path.join(__dirname, '/models')).forEach(file => {
|
|
23
|
-
if (file.match(/\.js/)) {
|
|
24
|
-
require(path.join(__dirname, '/models/', file))(mongoose)
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
}
|
package/models/banks.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const debug = require('debug')('model:banks')
|
|
4
|
-
|
|
5
|
-
module.exports = function (mongoose) {
|
|
6
|
-
const Schema = mongoose.Schema
|
|
7
|
-
const ObjectId = Schema.Types.ObjectId
|
|
8
|
-
|
|
9
|
-
const BankListSchema = new Schema({
|
|
10
|
-
name: { type: String, required: true },
|
|
11
|
-
creator_id: { type: ObjectId, ref: 'User', required: true },
|
|
12
|
-
description: { type: String },
|
|
13
|
-
preset_for: { type: String, required: true },
|
|
14
|
-
created_on: { type: Date, default: Date.now },
|
|
15
|
-
updated_on: { type: Date, default: Date.now }
|
|
16
|
-
}, { collection: 'bank_list' })
|
|
17
|
-
BankListSchema.index({
|
|
18
|
-
creator_id: 1,
|
|
19
|
-
preset_for: 1
|
|
20
|
-
})
|
|
21
|
-
const BankPresetsSchema = new Schema({
|
|
22
|
-
name: { type: String, index: true, required: true },
|
|
23
|
-
creator_id: { type: ObjectId, ref: 'User', required: true },
|
|
24
|
-
bank_id: { type: ObjectId, ref: 'BankList', required: true },
|
|
25
|
-
status: { type: Number, default: 1, required: true }, // 1:active
|
|
26
|
-
description: { type: String },
|
|
27
|
-
preset_data: { type: Schema.Types.Mixed, required: true },
|
|
28
|
-
preset_meta: { type: Schema.Types.Mixed },
|
|
29
|
-
image_url: { type: String },
|
|
30
|
-
thumb_url: { type: String },
|
|
31
|
-
created_on: { type: Date, default: Date.now },
|
|
32
|
-
updated_on: { type: Date, default: Date.now }
|
|
33
|
-
}, { collection: 'bank_presets', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
34
|
-
BankPresetsSchema.index({
|
|
35
|
-
creator_id: 1,
|
|
36
|
-
bank_id: 1,
|
|
37
|
-
name: 1
|
|
38
|
-
}, { unique: true })
|
|
39
|
-
|
|
40
|
-
mongoose.model('BankPresets', BankPresetsSchema)
|
|
41
|
-
mongoose.model('BankList', BankListSchema)
|
|
42
|
-
}
|
package/models/device.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = function (mongoose) {
|
|
4
|
-
const Schema = mongoose.Schema
|
|
5
|
-
const ObjectId = Schema.Types.ObjectId
|
|
6
|
-
|
|
7
|
-
var DeviceSchema = new Schema({
|
|
8
|
-
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
9
|
-
device_udid: { type: String, required: true, unique: true },
|
|
10
|
-
display_name: { type: String },
|
|
11
|
-
mac_address: { type: String },
|
|
12
|
-
machine_id: { type: String },
|
|
13
|
-
platform: { type: String },
|
|
14
|
-
architecture: { type: String },
|
|
15
|
-
os_version: { type: String },
|
|
16
|
-
model: { type: String },
|
|
17
|
-
activate_random: { type: String },
|
|
18
|
-
other_info: { type: String },
|
|
19
|
-
created_on: { type: Date, default: Date.now }
|
|
20
|
-
}, { collection: 'jamup_device' })
|
|
21
|
-
|
|
22
|
-
// main_product follow the iap defined in Product schema:
|
|
23
|
-
// extra_payment_fields.main_product
|
|
24
|
-
const IapActivationSchema = new Schema({
|
|
25
|
-
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
26
|
-
device_id: { type: ObjectId, ref: 'Device', required: true },
|
|
27
|
-
main_product: { type: String, required: true },
|
|
28
|
-
status: { type: Number, default: 1, required: true }, // 0:deactivate/1:activate
|
|
29
|
-
created_on: { type: Date, default: Date.now },
|
|
30
|
-
updated_on: { type: Date, default: Date.now }
|
|
31
|
-
}, { collection: 'iap_activation' })
|
|
32
|
-
|
|
33
|
-
var ActivationStatusSchema = new Schema({
|
|
34
|
-
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
35
|
-
device_id: { type: ObjectId, ref: 'Device', required: true },
|
|
36
|
-
license_id: { type: ObjectId, ref: 'License', required: true },
|
|
37
|
-
status: { type: Number, required: true }, // 0: inactive 1:active
|
|
38
|
-
created_on: { type: Date, default: Date.now },
|
|
39
|
-
updated_on: { type: Date, default: Date.now }
|
|
40
|
-
}, { collection: 'jamup_activationstatus' })
|
|
41
|
-
|
|
42
|
-
DeviceSchema.static({
|
|
43
|
-
getFeaturedPresetListByCondition: function (queryObj, cb) {
|
|
44
|
-
this.find(queryObj).select('-is_shown -order').exec(cb)
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
mongoose.model('Device', DeviceSchema)
|
|
49
|
-
mongoose.model('ActivationStatus', ActivationStatusSchema)
|
|
50
|
-
mongoose.model('IapActivation', IapActivationSchema)
|
|
51
|
-
}
|
package/models/featuredList.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash')
|
|
4
|
-
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');
|
|
5
|
-
|
|
6
|
-
module.exports = function (mongoose) {
|
|
7
|
-
const Schema = mongoose.Schema
|
|
8
|
-
const ObjectId = Schema.Types.ObjectId
|
|
9
|
-
|
|
10
|
-
const FeaturedListSchema = new Schema({
|
|
11
|
-
title: { type: String, required: true },
|
|
12
|
-
description: { type: String, default: null },
|
|
13
|
-
image_url: { type: String, default: null },
|
|
14
|
-
thumb_url: { type: String, default: null },
|
|
15
|
-
embed_url: { type: String, default: null },
|
|
16
|
-
bg_url: { type: String, default: null },
|
|
17
|
-
order: { type: Number, default: 0 },
|
|
18
|
-
type: { type: String, default: null },
|
|
19
|
-
permission: { type: Schema.Types.Mixed, default: null }, // product_id/custom_metadata
|
|
20
|
-
metadata: { type: Array, default: null },
|
|
21
|
-
is_shown: { type: Boolean, default: false },
|
|
22
|
-
list_for: { type: String, required: true, unique: true },
|
|
23
|
-
created_on: { type: Date, default: Date.now },
|
|
24
|
-
updated_on: { type: Date, default: Date.now }
|
|
25
|
-
}, { collection: 'jamup_featuredpresetlist', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
26
|
-
|
|
27
|
-
const FeaturedPresetSchema = new Schema({
|
|
28
|
-
featured_list_id: { type: ObjectId, ref: 'FeaturedList', required: true },
|
|
29
|
-
preset_id: { type: ObjectId, ref: 'Preset', required: true },
|
|
30
|
-
order: { type: Number, default: 0, required: true },
|
|
31
|
-
created_on: { type: Date, default: Date.now }
|
|
32
|
-
}, { collection: 'jamup_featuredpreset' })
|
|
33
|
-
|
|
34
|
-
FeaturedPresetSchema.index({
|
|
35
|
-
featured_list_id: 1,
|
|
36
|
-
preset_id: 1
|
|
37
|
-
}, { unique: true })
|
|
38
|
-
|
|
39
|
-
FeaturedListSchema.plugin(mongooseLeanVirtuals)
|
|
40
|
-
|
|
41
|
-
FeaturedListSchema.static({
|
|
42
|
-
getFeaturedPresetListByCondition: function (reqQuery) {
|
|
43
|
-
const defaultQuery = {
|
|
44
|
-
'$or': [
|
|
45
|
-
{permission: { '$exists': false }},
|
|
46
|
-
{permission: null }
|
|
47
|
-
],
|
|
48
|
-
is_shown: true,
|
|
49
|
-
list_for: 'jamup'
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const queryObj = (_.has(reqQuery, 'list_for'))
|
|
53
|
-
? _.assign({}, defaultQuery, { list_for: reqQuery['list_for'] })
|
|
54
|
-
: defaultQuery
|
|
55
|
-
|
|
56
|
-
return this.find(queryObj)
|
|
57
|
-
.sort({ order: 1 })
|
|
58
|
-
.select('-is_shown')
|
|
59
|
-
.lean({ virtuals: true })
|
|
60
|
-
.exec()
|
|
61
|
-
},
|
|
62
|
-
getLimitedPresetLists: function (reqQuery) {
|
|
63
|
-
const defaultQuery = {
|
|
64
|
-
'$and': [
|
|
65
|
-
{permission: { '$exists': true }},
|
|
66
|
-
{permission: { '$ne': null }}
|
|
67
|
-
],
|
|
68
|
-
is_shown: true,
|
|
69
|
-
list_for: 'jamup'
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const queryObj = (_.has(reqQuery, 'list_for'))
|
|
73
|
-
? _.assign({}, defaultQuery, { list_for: reqQuery['list_for'] })
|
|
74
|
-
: defaultQuery
|
|
75
|
-
|
|
76
|
-
return this.find(queryObj)
|
|
77
|
-
.sort({ order: 1 })
|
|
78
|
-
.select('-is_shown')
|
|
79
|
-
.lean({ virtuals: true })
|
|
80
|
-
.exec()
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
FeaturedListSchema.virtual('id')
|
|
85
|
-
.get(function () {
|
|
86
|
-
return this._id.toHexString()
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
mongoose.model('FeaturedList', FeaturedListSchema)
|
|
90
|
-
mongoose.model('FeaturedPreset', FeaturedPresetSchema)
|
|
91
|
-
}
|
package/models/hardware.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash')
|
|
4
|
-
const debug = require('debug')('model:promo')
|
|
5
|
-
|
|
6
|
-
module.exports = function (mongoose) {
|
|
7
|
-
const Schema = mongoose.Schema
|
|
8
|
-
const ObjectId = Schema.Types.ObjectId
|
|
9
|
-
|
|
10
|
-
const HardwareSeriesNumberSchema = new Schema({
|
|
11
|
-
hw_sn: { type: String, required: true },
|
|
12
|
-
channel: { type: String, default: null }, // Hardware sales channel: amazon
|
|
13
|
-
status: { type: 'Number', default: 1 }, //1:normal/2:deactived/3:blacklist
|
|
14
|
-
metadata: { type: Schema.Types.Mixed },
|
|
15
|
-
created_on: { type: Date, default: Date.now }
|
|
16
|
-
}, { collection: 'hardware_seriesnumber' })
|
|
17
|
-
|
|
18
|
-
const HardwareActivationMetaSchema = new Schema({
|
|
19
|
-
pattern: { type: Array, required: true },
|
|
20
|
-
hw_sn_pattern: { type: Schema.Types.Mixed, required: true }, // pattern detail can jump to parseHardwareSeriesNumber
|
|
21
|
-
hw_activate_license: [{ type: ObjectId, ref: 'Product' }],
|
|
22
|
-
status: { type: Number, required: true, default: 1 }, // 1:enable 2:disable
|
|
23
|
-
created_on: { type: Date, default: Date.now }
|
|
24
|
-
}, { collection: 'hardware_activation_meta' })
|
|
25
|
-
|
|
26
|
-
const HardwareActivationRecordSchema = new Schema({
|
|
27
|
-
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
28
|
-
hw_sn_id: { type: ObjectId, ref: 'HardwareSeriesNumber', required: true },
|
|
29
|
-
hw_meta_id: { type: ObjectId, ref: 'HardwareActivationMeta', default: null },
|
|
30
|
-
hw_partner_id: { type: ObjectId, ref: 'PartnerCoupon', default: null },
|
|
31
|
-
activate_license: [{ type: ObjectId, ref: 'License' }],
|
|
32
|
-
status: { type: Number, required: true, default: 1 }, // 1:activate 2:deactivate
|
|
33
|
-
activate_on: { type: Date, default: Date.now }
|
|
34
|
-
}, { collection: 'hardware_activation_record' })
|
|
35
|
-
|
|
36
|
-
const HardwareActivationConflictSchema = new Schema({
|
|
37
|
-
user_id: { type: ObjectId, ref: 'User', required: true },
|
|
38
|
-
hw_sn_id: { type: ObjectId, ref: 'HardwareSeriesNumber', required: true },
|
|
39
|
-
created_on: { type: Date, default: Date.now }
|
|
40
|
-
}, { collection: 'hardware_activation_conflict' })
|
|
41
|
-
|
|
42
|
-
const PartnerCouponSchema = new Schema({
|
|
43
|
-
partner: { type: String, required: true },
|
|
44
|
-
code: { type: String, required: true },
|
|
45
|
-
status: { type: Number, default: 1, required: true },
|
|
46
|
-
hw_sn_id: { type: ObjectId, ref: 'HardwareSeriesNumber' },
|
|
47
|
-
created_on: { type: Date, default: Date.now }
|
|
48
|
-
}, { collection: 'partner_coupon' })
|
|
49
|
-
|
|
50
|
-
const WarehouseInventorySchema = new Schema({
|
|
51
|
-
warehouse: { type: String, required: true },
|
|
52
|
-
country: [{ type: String }],
|
|
53
|
-
status: { type: Number, default: 1, required: true },
|
|
54
|
-
items: [{
|
|
55
|
-
sku: { type: String, required: true },
|
|
56
|
-
type: { type: String, required: true },
|
|
57
|
-
total: { type: Number, required: true },
|
|
58
|
-
available: { type: Number, required: true },
|
|
59
|
-
transit: { type: Number, required: true },
|
|
60
|
-
lock: { type: Number, required: true }
|
|
61
|
-
}],
|
|
62
|
-
created_on: { type: Date, default: Date.now }
|
|
63
|
-
}, { collection: 'warehouse_inventory' })
|
|
64
|
-
WarehouseInventorySchema.index({ warehouse: 1 }, { unique: true })
|
|
65
|
-
WarehouseInventorySchema.index({ country: 1 })
|
|
66
|
-
|
|
67
|
-
const ItemInventoryHistorySchema = new Schema({
|
|
68
|
-
warehouse: { type: String, required: true },
|
|
69
|
-
sku: { type: String, required: true },
|
|
70
|
-
total: { type: Number, required: true },
|
|
71
|
-
available: { type: Number, required: true },
|
|
72
|
-
transit: { type: Number, required: true },
|
|
73
|
-
lock: { type: Number, required: true },
|
|
74
|
-
created_on: { type: Date, default: Date.now }
|
|
75
|
-
}, { collection: 'item_inventory_history' })
|
|
76
|
-
ItemInventoryHistorySchema.index({ warehouse: 1, sku: 1 })
|
|
77
|
-
|
|
78
|
-
const CountryHardwareSkuSchema = new Schema({
|
|
79
|
-
country: [{ type: String }],
|
|
80
|
-
items: [{
|
|
81
|
-
name: { type: String },
|
|
82
|
-
hw_sku: [{ type: String }]
|
|
83
|
-
}],
|
|
84
|
-
level: [{
|
|
85
|
-
level: { type: Number },
|
|
86
|
-
min: { type: Number },
|
|
87
|
-
max: { type: Number },
|
|
88
|
-
days: { type: String }
|
|
89
|
-
}],
|
|
90
|
-
sale_threshold: { type: Number },
|
|
91
|
-
sale_region: { type: String },
|
|
92
|
-
sale_overwrite: [{
|
|
93
|
-
level: { type: Number },
|
|
94
|
-
days: { type: String }
|
|
95
|
-
}],
|
|
96
|
-
not_sold: [{ type: String }],
|
|
97
|
-
not_sold_threshold: { type: Number },
|
|
98
|
-
express_ship_days: { type: String },
|
|
99
|
-
status: { type: Number, default: 1 }, //1:valid/2:preorder
|
|
100
|
-
created_on: { type: Date, default: Date.now }
|
|
101
|
-
}, { collection: 'country_hardaware_sku' })
|
|
102
|
-
|
|
103
|
-
function _identifyHardwareByModel(model) {
|
|
104
|
-
switch (model) {
|
|
105
|
-
case 'G1':
|
|
106
|
-
return 'head'
|
|
107
|
-
case 'G2':
|
|
108
|
-
return 'rack'
|
|
109
|
-
case 'G3':
|
|
110
|
-
return 'mini'
|
|
111
|
-
case 'S':
|
|
112
|
-
return 'spark'
|
|
113
|
-
default:
|
|
114
|
-
return false
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function _parseHardwareSerialNumber(hwSn) {
|
|
119
|
-
if (!_.isString(hwSn)) {
|
|
120
|
-
throw Error(`Invalid hardware series number format: ${hwSn}`)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Separate Spark with different Serial Number format
|
|
124
|
-
// old: https://docs.google.com/spreadsheets/d/1JGUigUU4UhY4ZWUDEhzQCDlKOd7Z5nHfHbFLw8riCsM/edit#gid=1816344881
|
|
125
|
-
// new: https://docs.google.com/spreadsheets/d/1AZhKe2_M6kJ3lGqEUEWCN24ziOnW5gmV-DrV_mV2GEY/edit#gid=432186548
|
|
126
|
-
if (/^S/.test(hwSn)) {
|
|
127
|
-
const hwModel = hwSn.slice(0, 1)
|
|
128
|
-
const hwWattage = hwSn.slice(1, 4)
|
|
129
|
-
const hwProductType = hwSn.slice(4, 5)
|
|
130
|
-
const hwVersion = hwSn.slice(5, 6)
|
|
131
|
-
const hwYear = hwSn.slice(6, 7)
|
|
132
|
-
const hwMonth = hwSn.slice(7, 8)
|
|
133
|
-
const hwPattern = [
|
|
134
|
-
`hwModel:${hwModel}`,
|
|
135
|
-
`hwWattage:${hwWattage}`,
|
|
136
|
-
`hwProductType:${hwProductType}`,
|
|
137
|
-
`hwVersion:${hwVersion}`,
|
|
138
|
-
`hwYear:${hwYear}`,
|
|
139
|
-
`hwMonth:${hwMonth}`
|
|
140
|
-
]
|
|
141
|
-
|
|
142
|
-
const hwName = _identifyHardwareByModel(hwModel)
|
|
143
|
-
if (hwName === false) {
|
|
144
|
-
throw Error(`Cannot identify hardware model: ${hwModel}`)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
hwName,
|
|
149
|
-
hwModel,
|
|
150
|
-
hwWattage,
|
|
151
|
-
hwProductType,
|
|
152
|
-
hwVersion,
|
|
153
|
-
hwYear,
|
|
154
|
-
hwMonth,
|
|
155
|
-
hwPattern
|
|
156
|
-
}
|
|
157
|
-
} else {
|
|
158
|
-
const hwModel = hwSn.slice(0, 2)
|
|
159
|
-
const hwWattage = hwSn.slice(2, 4)
|
|
160
|
-
const hwVersion = hwSn.slice(4, 7)
|
|
161
|
-
const hwProductionPhase = hwSn.slice(7, 9)
|
|
162
|
-
const hwName = _identifyHardwareByModel(hwModel)
|
|
163
|
-
const hwPattern = [
|
|
164
|
-
`hwModel:${hwModel}`,
|
|
165
|
-
`hwWattage:${hwWattage}`,
|
|
166
|
-
`hwVersion:${hwVersion}`,
|
|
167
|
-
`hwProductionPhase:${hwProductionPhase}`
|
|
168
|
-
]
|
|
169
|
-
|
|
170
|
-
if (hwName === false) {
|
|
171
|
-
throw Error(`Cannot identify hardware model: ${hwModel}`)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
hwModel,
|
|
176
|
-
hwWattage,
|
|
177
|
-
hwVersion,
|
|
178
|
-
hwProductionPhase,
|
|
179
|
-
hwName,
|
|
180
|
-
hwPattern
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
HardwareSeriesNumberSchema.static({
|
|
186
|
-
// doc: https://docs.google.com/spreadsheets/d/1JGUigUU4UhY4ZWUDEhzQCDlKOd7Z5nHfHbFLw8riCsM/edit#gid=1816344881
|
|
187
|
-
parseHardwareSeriesNumber: function (hwSn) {
|
|
188
|
-
return new Promise((resolve, reject) => {
|
|
189
|
-
try {
|
|
190
|
-
const ret = _parseHardwareSerialNumber(hwSn)
|
|
191
|
-
return resolve(ret)
|
|
192
|
-
} catch (e) {
|
|
193
|
-
return reject(e)
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
},
|
|
197
|
-
parseHardwareSerialNumberNoPromise: function (hwSn) {
|
|
198
|
-
try {
|
|
199
|
-
return _parseHardwareSerialNumber(hwSn)
|
|
200
|
-
} catch (e) {
|
|
201
|
-
return e.message
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
HardwareActivationMetaSchema.static({
|
|
207
|
-
findMostMatchingMeta: async function (snPatternArr, opts = {}) {
|
|
208
|
-
try {
|
|
209
|
-
let allMatch = await this.find({ pattern: { '$in': snPatternArr } }).sort({ created_on: -1 }).lean().exec()
|
|
210
|
-
|
|
211
|
-
if (!allMatch || allMatch.length <= 0) {
|
|
212
|
-
if (opts.allowEmpty && opts.allowEmpty === true) {
|
|
213
|
-
return null
|
|
214
|
-
} else {
|
|
215
|
-
throw new Error('Cannot find any activation meta match the SN pattern')
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
let mostMatchingMeta = {}
|
|
220
|
-
let mostMatchingNumber = 0
|
|
221
|
-
allMatch.forEach(metaItem => {
|
|
222
|
-
if (_.isArray(metaItem.pattern) && metaItem.pattern.length > 0) {
|
|
223
|
-
let matchItem = _.intersection(metaItem.pattern, snPatternArr)
|
|
224
|
-
if ((matchItem.length === metaItem.pattern.length) &&
|
|
225
|
-
(matchItem.length > mostMatchingNumber)) {
|
|
226
|
-
mostMatchingMeta = metaItem
|
|
227
|
-
mostMatchingNumber = matchItem.length
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
if (_.isEmpty(mostMatchingMeta) || mostMatchingNumber === 0) {
|
|
233
|
-
if (opts.allowEmpty && opts.allowEmpty === true) {
|
|
234
|
-
return null
|
|
235
|
-
} else {
|
|
236
|
-
throw new Error('Cannot find any activation meta match the SN pattern')
|
|
237
|
-
}
|
|
238
|
-
} else {
|
|
239
|
-
return mostMatchingMeta
|
|
240
|
-
}
|
|
241
|
-
} catch (err) {
|
|
242
|
-
debug('ERROR:findMostMatchingMeta %o', err)
|
|
243
|
-
throw err
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
mongoose.model('HardwareActivationRecord', HardwareActivationRecordSchema)
|
|
249
|
-
mongoose.model('HardwareActivationMeta', HardwareActivationMetaSchema)
|
|
250
|
-
mongoose.model('HardwareSeriesNumber', HardwareSeriesNumberSchema)
|
|
251
|
-
mongoose.model('HardwareActivationConflict', HardwareActivationConflictSchema)
|
|
252
|
-
mongoose.model('PartnerCoupon', PartnerCouponSchema)
|
|
253
|
-
mongoose.model('WarehouseInventory', WarehouseInventorySchema)
|
|
254
|
-
mongoose.model('ItemInventoryHistory', ItemInventoryHistorySchema)
|
|
255
|
-
mongoose.model('CountryHardwareSku', CountryHardwareSkuSchema)
|
|
256
|
-
}
|
package/models/homeConfig.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
module.exports = function (mongoose) {
|
|
4
|
-
const Schema = mongoose.Schema;
|
|
5
|
-
|
|
6
|
-
const DataSourceSchema = new Schema(
|
|
7
|
-
{
|
|
8
|
-
type: {
|
|
9
|
-
type: String,
|
|
10
|
-
enum: ["tone_theme_query", "tone_theme_ids", "tone_theme_id"],
|
|
11
|
-
required: true,
|
|
12
|
-
},
|
|
13
|
-
// 單一 theme ID(當 type = 'tone_theme_id')
|
|
14
|
-
tone_theme_id: {
|
|
15
|
-
type: String,
|
|
16
|
-
default: null,
|
|
17
|
-
},
|
|
18
|
-
// 動態查詢(當 type = 'tone_theme_query')
|
|
19
|
-
query: {
|
|
20
|
-
type: Schema.Types.Mixed,
|
|
21
|
-
default: null,
|
|
22
|
-
},
|
|
23
|
-
// 多個 theme IDs(當 type = 'tone_theme_ids')
|
|
24
|
-
ids: [
|
|
25
|
-
{
|
|
26
|
-
type: String,
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
limit: {
|
|
30
|
-
type: Number,
|
|
31
|
-
default: 12,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
{ _id: false }
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const SectionSchema = new Schema(
|
|
38
|
-
{
|
|
39
|
-
section_type: {
|
|
40
|
-
type: String,
|
|
41
|
-
enum: ["tone_theme_banner", "tone_theme_list", "tone_theme_lists"],
|
|
42
|
-
required: true,
|
|
43
|
-
},
|
|
44
|
-
title: {
|
|
45
|
-
type: String,
|
|
46
|
-
default: null,
|
|
47
|
-
},
|
|
48
|
-
order: {
|
|
49
|
-
type: Number,
|
|
50
|
-
required: true,
|
|
51
|
-
},
|
|
52
|
-
data_source: {
|
|
53
|
-
type: DataSourceSchema,
|
|
54
|
-
required: true,
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
{ _id: false }
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const HomeConfigSchema = new Schema(
|
|
61
|
-
{
|
|
62
|
-
config_for: {
|
|
63
|
-
type: String,
|
|
64
|
-
required: true,
|
|
65
|
-
},
|
|
66
|
-
locale: {
|
|
67
|
-
type: String,
|
|
68
|
-
default: "en",
|
|
69
|
-
},
|
|
70
|
-
sections: [SectionSchema],
|
|
71
|
-
is_active: {
|
|
72
|
-
type: Boolean,
|
|
73
|
-
default: false,
|
|
74
|
-
},
|
|
75
|
-
created_on: {
|
|
76
|
-
type: Date,
|
|
77
|
-
default: Date.now,
|
|
78
|
-
},
|
|
79
|
-
updated_on: {
|
|
80
|
-
type: Date,
|
|
81
|
-
default: Date.now,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
collection: "home_config",
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
// 索引
|
|
90
|
-
HomeConfigSchema.index({
|
|
91
|
-
config_for: 1,
|
|
92
|
-
locale: 1,
|
|
93
|
-
is_active: 1,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
mongoose.model("HomeConfig", HomeConfigSchema);
|
|
97
|
-
};
|
package/models/oauth.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = function (mongoose) {
|
|
4
|
-
const Schema = mongoose.Schema
|
|
5
|
-
const ObjectId = Schema.Types.ObjectId
|
|
6
|
-
const deepPopulate = require('mongoose-deep-populate')(mongoose)
|
|
7
|
-
|
|
8
|
-
const clientSchema = new Schema({
|
|
9
|
-
name: { type: String, required: true },
|
|
10
|
-
clientId: { type: String, required: true },
|
|
11
|
-
clientSecret: { type: String, required: true }
|
|
12
|
-
}, { collection: 'auth_clients', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
13
|
-
|
|
14
|
-
// auth_ authorizationCodes
|
|
15
|
-
const AuthorizationCodeSchema = new Schema({
|
|
16
|
-
code: { type: String, required: true },
|
|
17
|
-
clientId: { type: ObjectId, ref: 'OathClient', required: true },
|
|
18
|
-
redirectURI: { type: String, required: true },
|
|
19
|
-
userId: { type: ObjectId, ref: 'User', required: true },
|
|
20
|
-
scopes: [{ type: String, required: true }],
|
|
21
|
-
expiresAt: { type: Date, required: true },
|
|
22
|
-
codeChallenge: { type: String },
|
|
23
|
-
codeChallengeMethod: { type: String, default: 'S256' },
|
|
24
|
-
date: { type: Date, default: Date.now }
|
|
25
|
-
}, { collection: 'auth_authorizationCodes', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
26
|
-
AuthorizationCodeSchema.plugin(deepPopulate, {})
|
|
27
|
-
|
|
28
|
-
// auth_accessTokens
|
|
29
|
-
const AccessTokenSchema = new Schema({
|
|
30
|
-
token: { type: String, required: true },
|
|
31
|
-
expirationDate: { type: Date, required: true },
|
|
32
|
-
userId: { type: ObjectId, ref: 'User', required: true },
|
|
33
|
-
clientId: { type: ObjectId, ref: 'OathClient', required: true },
|
|
34
|
-
scopes: [{ type: String, required: true }],
|
|
35
|
-
date: { type: Date, default: Date.now }
|
|
36
|
-
}, { collection: 'auth_accessTokens', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
37
|
-
|
|
38
|
-
// refreshTokens
|
|
39
|
-
const RefreshTokenSchema = new Schema({
|
|
40
|
-
refreshToken: { type: String, required: true },
|
|
41
|
-
clientId: { type: ObjectId, ref: 'OathClient', required: true },
|
|
42
|
-
expirationDate: { type: Date, required: true },
|
|
43
|
-
userId: { type: ObjectId, ref: 'User', required: true },
|
|
44
|
-
scopes: [{ type: String, required: true }],
|
|
45
|
-
date: { type: Date, default: Date.now }
|
|
46
|
-
}, { collection: 'auth_refreshTokens', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
47
|
-
|
|
48
|
-
mongoose.model('OauthClient', clientSchema)
|
|
49
|
-
mongoose.model('RefreshTokens', RefreshTokenSchema)
|
|
50
|
-
mongoose.model('AccessToken', AccessTokenSchema)
|
|
51
|
-
mongoose.model('AuthorizationCode', AuthorizationCodeSchema)
|
|
52
|
-
}
|