-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapplication.js
More file actions
146 lines (137 loc) · 3.85 KB
/
Copy pathapplication.js
File metadata and controls
146 lines (137 loc) · 3.85 KB
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
/**
* application
*
* @author hyczzhu
*/
const Mock = require('mockjs')
const config = require('../utils/config')
const { apiPrefix } = config
let applicationData = Mock.mock({
'data|80-100': [
{
app_id: '@id',
app_name: '@domain',
app_desc: '@title',
status2 () {
return Mock.mock({
'data|1': [
'active',
'pending',
'paused',
],
}).data
},
platform () {
return Mock.mock({
'data|1': [
'pc-web',
'wap-web',
'mobile-app',
],
}).data
},
web_type () {
return Mock.mock({
'data|1': [
'forum',
'news',
'exchange',
],
}).data
},
web_url: '@url',
pv: '@integer',
uv: '@integer',
app_type () {
return Mock.mock({
'data|1': [
'business',
'catalogs',
'education',
'entertainment',
'finance',
'food_drink',
'games',
'health_fitness',
'lifestyle',
'medical',
'music',
'navigation',
'news',
'photo_video',
'productivity',
'reference',
'social_networking',
'sports',
'travel',
'utilities',
'weather',
'adult',
],
}).data
},
app_platform () {
return Mock.mock({
'data|1': [
'ios',
'android',
],
}).data
},
package_name: '@title',
store_url: '@url',
dau: '@integer',
},
],
})
const database = applicationData.data
// const queryArray = (array, key, keyAlias = 'key') => {
// if (!(array instanceof Array)) {
// return null
// }
// let data
//
// for (let item of array) {
// if (item[keyAlias] === key) {
// data = item
// break
// }
// }
//
// if (data) {
// return data
// }
// return null
// }
// const NOTFOUND = {
// message: 'Not Found',
// documentation_url: 'http://localhost:8000/request',
// }
module.exports = {
[`GET ${apiPrefix}/application`] (req, res) {
const { query } = req
let { pageSize, page, ...other } = query
pageSize = pageSize || 10
page = page || 1
let newData = database
for (let key in other) {
if ({}.hasOwnProperty.call(other, key)) {
newData = newData.filter((item) => {
if ({}.hasOwnProperty.call(item, key)) {
return String(item[key]).trim().indexOf(decodeURI(other[key]).trim()) > -1
}
return true
})
}
}
res.status(200).json({
data: newData.slice((page - 1) * pageSize, page * pageSize).map(item => {
return {
...item,
status: item.status2,
}
}),
total: newData.length,
})
},
}