mirror of
https://github.com/UniversityOfHelsinkiCS/ohtuilmo.git
synced 2026-10-12 19:03:41 +03:00
Merge pull request #51 from ohtuprojekti-ilmo/topic-service-fixes
changed topic services a bit + some code cleanup
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user