Merge pull request #51 from ohtuprojekti-ilmo/topic-service-fixes

changed topic services a bit + some code cleanup
This commit is contained in:
vasdf
2018-11-23 13:34:38 +02:00
committed by GitHub
3 changed files with 7 additions and 9 deletions
+2 -2
View File
@@ -15,7 +15,7 @@ class TopicFormPage extends React.Component {
event.preventDefault()
try {
const content = { content: this.props.content }
const response = await topicService.create(content)
const createdTopic = await topicService.create(content)
this.props.setSuccess('Topic proposal submitted succesfully!')
setTimeout(() => {
@@ -23,7 +23,7 @@ class TopicFormPage extends React.Component {
}, 3000)
this.props.clearForm()
this.props.updateSecretId(response.topic.secret_id)
this.props.updateSecretId(createdTopic.secret_id)
this.props.setSaved(true)
} catch (e) {
console.log('error happened', e.response)
+1 -3
View File
@@ -16,9 +16,7 @@ class TopicListPage extends React.Component {
async componentDidMount() {
try {
const fetchedTopics = await topicService.getAll().then(function (defs) {
return defs
})
const fetchedTopics = await topicService.getAll()
//sorts topics based on timestamp
const sortedTopics = fetchedTopics.sort((t1, t2) =>
t1.createdAt > t2.createdAt ? -1 : t1.createdAt < t2.createdAt ? 1 : 0
+4 -4
View File
@@ -5,7 +5,7 @@ const url = `${BACKEND_URI}/api/topics`
const create = async (content) => {
const response = await axios.post(url, content)
return response.data
return response.data.topic
}
const getAll = async () => {
@@ -18,7 +18,7 @@ const getAll = async () => {
headers: { 'Authorization': 'bearer ' + token }
}
const response = await axios.get(url, config)
return response.data
return response.data.topics
}
const update = async (topic) => {
@@ -31,12 +31,12 @@ const update = async (topic) => {
headers: { 'Authorization': 'bearer ' + token }
}
const response = await axios.put(url + '/' + topic.id, topic, config)
return response.data
return response.data.topic
}
const getOne = async (id) => {
const response = await axios.get(url + '/' + id)
return response.data
return response.data.topic
}
export default { create, getAll, getOne , update }