-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
198 lines (186 loc) · 6.35 KB
/
server.js
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
const faker = require('faker')
const { token, status, banks, method } = require('./vars')
/**
* @param Array arr
*/
const shuffleArray = arr =>
arr
.map(a => [Math.random(), a])
.sort((a, b) => a[0] - b[0])
.map(a => a[1])
const user = {
id: faker.random.number(999),
name: faker.name.findName(),
email: faker.internet.email()
}
const monthlyMetrics = [...Array(6)].map((v, i) => ({
files_info: [...Array(6)].map((value, index) => ({
id: index + 1,
month: 12 - index,
total: faker.random.number(900),
new: faker.random.number(10),
without_return: faker.random.number(10),
expired: faker.random.number(10)
})),
meta: {
current_page: (i + 1),
next_page: (i < 5 ? i + 2 : i + 1),
page_records: 6,
total_records: 6
}
}))
const bankFiles = {
type: 'debit',
files: [...Array(50)].map((value, index) => ({
id: index + 1,
status: shuffleArray(status)[0],
bank: shuffleArray(banks)[0],
amount: faker.random.number(100),
max_date_to_send: faker.date.between('2019-08-01', '2019-07-01'),
expires_in: faker.date.between('2019-08-01', '2019-07-01')
}))
}
const generateBankFile = { url: faker.internet.url() }
const importBankFile = { status: 'success' }
const payments = [...Array(20)].map((v, i) => ({
id: faker.random.uuid(),
status: shuffleArray(status)[0],
date: faker.date.recent(),
donor: { name: faker.name.findName() },
method: {
type: shuffleArray(method.type)[0],
card: {
brand: shuffleArray(method.brands)[0],
}
},
value: faker.finance.amount(3000, 99999, 0),
currency: 'BRL'
}))
const successfulPayments = faker.random.number(99999)
const hardBounces = faker.random.number(9999)
const softBounces = faker.random.number(9999)
const refunds = faker.random.number(999)
const totalAmount = (successfulPayments + hardBounces + softBounces + refunds)
const generalInfo = {
// '_endpoint': '/admin/general_info',
'successful_payments_amount': successfulPayments,
'hard_bounces_amount': hardBounces,
'soft_bounces_amount': softBounces,
'refunds_amount': refunds,
'total_amount': totalAmount,
'chargebacks_count': 1,
'charges_count': faker.random.number(9999),
'effectiveness_rate': 97.5
}
const uniqueDonations = faker.random.number(9999)
const recurringDonations = faker.random.number(9999)
const canceledDonations = faker.random.number(9999)
const pausedDonations = faker.random.number(9999)
const totalDonationsCount = (uniqueDonations + recurringDonations + canceledDonations + pausedDonations)
const totalDonations = {
// '_endpoint': '/admin/total_donations',
'unique_donations_count': uniqueDonations,
'recurring_donations_count': recurringDonations,
'canceled_donations_count': canceledDonations,
'paused_donations_count': pausedDonations,
'total_donations_count': totalDonationsCount,
'donations_per_month': {
'2018/07': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2018/08': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2018/09': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2018/10': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2018/11': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2018/12': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2019/01': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2019/02': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(999),
'canceled_count': faker.random.number(999),
'paused_count': faker.random.number(999)
},
'2019/03': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2019/04': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2019/05': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
},
'2019/06': {
'unique_count': faker.random.number(999),
'recurring_count': faker.random.number(99),
'canceled_count': faker.random.number(99),
'paused_count': faker.random.number(9999)
}
}
}
const cohortData = {
// '2018/08': [ 807, 807, 636, 521, 422, 381, 321, 212, 185, 142, 122, 51, 15 ],
// '2018/09': [ 782, 782, 613, 502, 405, 325, 302, 198, 165, 122, 85, 12 ],
// '2018/10': [ 762, 762, 592, 482, 377, 295, 274, 175, 133, 87, 32 ],
// '2018/11': [ 741, 741, 572, 461, 364, 287, 265, 154, 128, 35 ],
'2018/12': [ 737, 737, 556, 432, 321, 254, 232, 182, 102 ],
'2019/01': [ 707, 707, 656, 0, 321, 254, 232, 102 ],
'2019/02': [ 693, 693, 510, 386, 0, 221, 187 ],
'2019/03': [ 675, 675, 0, 362, 230, 195 ],
'2019/04': [ 659, 659, 472, 342, 187 ],
'2019/05': [ 632, 632, 456, 316 ],
'2019/06': [ 612, 612, 431 ],
'2019/07': [ 587, 587 ]
}
module.exports = () => ({
token: { ...token, ...{ user } },
monthly_metrics: monthlyMetrics,
bank_files: bankFiles,
generate_bank_file: generateBankFile,
import_bank_file: importBankFile,
payments,
general_info: generalInfo,
total_donations: totalDonations,
cohort_data: cohortData
})