getPerson endpoint and is called properly when movie.vue opens with type 'person'.
This commit is contained in:
19
src/api.js
19
src/api.js
@@ -48,6 +48,24 @@ const getShow = (id, credits=false) => {
|
|||||||
.catch(error => { console.error(`api error getting show: ${id}`); throw error })
|
.catch(error => { console.error(`api error getting show: ${id}`); throw error })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches tmdb person by id. Can optionally include cast credits in result object.
|
||||||
|
* @param {number} id
|
||||||
|
* @param {boolean} [credits=false] Include credits
|
||||||
|
* @returns {object} Tmdb response
|
||||||
|
*/
|
||||||
|
const getPerson = (id, credits=false) => {
|
||||||
|
const url = new URL('v2/person', SEASONED_URL)
|
||||||
|
url.pathname = path.join(url.pathname, id.toString())
|
||||||
|
if (credits) {
|
||||||
|
url.searchParams.append('credits', true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fetch(url.href)
|
||||||
|
.then(resp => resp.json())
|
||||||
|
.catch(error => { console.error(`api error getting person: ${id}`); throw error })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches tmdb list by name.
|
* Fetches tmdb list by name.
|
||||||
* @param {string} name List the fetch
|
* @param {string} name List the fetch
|
||||||
@@ -295,6 +313,7 @@ const elasticSearchMoviesAndShows = (query) => {
|
|||||||
export {
|
export {
|
||||||
getMovie,
|
getMovie,
|
||||||
getShow,
|
getShow,
|
||||||
|
getPerson,
|
||||||
getTmdbMovieListByName,
|
getTmdbMovieListByName,
|
||||||
searchTmdb,
|
searchTmdb,
|
||||||
getUserRequests,
|
getUserRequests,
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ import SidebarListElement from './ui/sidebarListElem'
|
|||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
import LoadingPlaceholder from './ui/LoadingPlaceholder'
|
import LoadingPlaceholder from './ui/LoadingPlaceholder'
|
||||||
|
|
||||||
import { getMovie, getShow, request, getRequestStatus } from '@/api'
|
import { getMovie, getPerson, getShow, request, getRequestStatus } from '@/api'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['id', 'type'],
|
props: ['id', 'type'],
|
||||||
@@ -205,6 +205,12 @@ export default {
|
|||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.$router.push({ name: '404' });
|
this.$router.push({ name: '404' });
|
||||||
})
|
})
|
||||||
|
} else if (this.type == 'person') {
|
||||||
|
getPerson(this.id, true)
|
||||||
|
.then(this.parseResponse)
|
||||||
|
.catch(error => {
|
||||||
|
this.$router.push({ name: '404' });
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
getShow(this.id)
|
getShow(this.id)
|
||||||
.then(this.parseResponse)
|
.then(this.parseResponse)
|
||||||
|
|||||||
Reference in New Issue
Block a user