-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
products.coffee
112 lines (93 loc) · 2.03 KB
/
products.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Product = require '../models/Product'
errors = require '../commons/errors'
config = require '../../server_config'
wrap = require 'co-express'
get = wrap (req, res) ->
products = yield Product.find().lean()
unless _.size(products) or config.isProduction
products = productStubs
if req.features.china
products = _.filter(products, (product) ->
return true if product.name is 'lifetime_subscription'
product.name.indexOf('subscription') is -1
)
return res.send(products)
if (req.user.get('testGroupNumber') or 0) % 2 is 0
products = (p for p in products when p.name isnt 'year_subscription')
else
products = (p for p in products when p.name isnt 'lifetime_subscription')
res.send(products)
###
Stub data, used in tests and dev environment.
These values are only upserted when the test/dev db does not already contain them.
If you are testing products and need to change them, you'll need to edit the db values directly.
###
productStubs = [
{
name: 'gems_5'
amount: 100
gems: 5000
priceString: '$1.00'
i18n: 'buy_gems.few_gems'
}
{
name: 'gems_10'
amount: 101
gems: 11000
priceString: '$1.01'
i18n: 'buy_gems.pile_gems'
}
{
name: 'gems_20'
amount: 102
gems: 25000
priceString: '$1.02'
i18n: 'buy_gems.chest_gems'
}
{
name: 'custom'
type: 'purchase'
}
{
name: 'basic_subscription'
amount: 100
gems: 3500
planID: 'basic'
}
{
name: 'year_subscription'
amount: 1000
gems: 42000
}
{
name: 'prepaid_subscription'
amount: 100
gems: 3500
}
{
name: 'course'
amount: 100
}
{
name: 'starter_license'
amount: 100
}
{
name: 'brazil_basic_subscription'
amount: 0
gems: 1500
planID: 'basic'
}
{
name: 'lifetime_subscription'
amount: 1000
gems: 42000
}
]
# For Backbone collection in dev environment, otherwise models merge
for productStub in productStubs
productStub._id = _.uniqueId()
module.exports = {
get
productStubs
}