Extend remote to accept post id

master
Raymonzut 4 years ago
parent 5a9de29169
commit 3b22f15a45
No known key found for this signature in database
GPG Key ID: 97CF2D8BE2C69FC7
  1. 17
      client/src/remote.js

@ -1,9 +1,20 @@
module.exports = {
getPosts: function() {
getPosts: function(id) {
const BASE_URL = 'http://localhost:5000/api/posts'
const URL = BASE_URL + (id ? `/${id}` : '?sort=-1')
this.$http
.get('http://localhost:5000/api/posts?sort=-1')
.get(URL)
.then(res => {
this.posts = res.body
if (id) {
if (res.body.length === 0) {
throw Error("Response body empty")
}
this.post = res.body[0]
}
else {
this.posts = res.body
}
})
.catch(err => {
console.log(`Error: ${err}`)

Loading…
Cancel
Save