forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopicService.js
More file actions
80 lines (71 loc) · 1.44 KB
/
topicService.js
File metadata and controls
80 lines (71 loc) · 1.44 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
import * as requestService from './request'
import {getToken, setToken} from './token'
function filterData (data) {
return data.data
}
export function getTopicsByTab (tab = 'all', params = {}) {
return requestService.get('/topics', {
tab,
page: 1,
limit: 10,
...params
})
.then(filterData)
}
export function getTopicById (id) {
return requestService.get('/topic/' + id)
.then(filterData)
.then(topic => {
if (topic && topic.id) {
return topic
}
throw 'getTopicById Error'
})
}
export function reply ({topicId, content, replyId}) {
let body = {
accesstoken: getToken(),
content: content
}
if (replyId) {
body.reply_id = replyId
}
let url = `/topic/${topicId}/replies`
return requestService.post(url, body)
.then(data => {
if (data.success) {
return data.reply_id
} else {
throw 'do reply failed'
}
})
}
export function upReply ({replyId}) {
let body = {
accesstoken: getToken()
}
let url = `/reply/${replyId}/ups`
return requestService.post(url, body)
.then(data => {
if (data.success) {
return data.action == 'up'
} else {
throw 'up reply failed'
}
})
}
export function publish ({title, tab, content}) {
const body = {
title: title,
tab: tab,
content: content,
accesstoken: getToken()
}
return requestService.post('/topics', body)
.then(data => {
if (data.success) {
return data.topic_id
}
throw 'publish failed'
})
}