Do not use undefined params
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { DetailedCollection, ImageCollection, LanguageOption, Translations } from '../types';
|
||||
import { BaseEndpoint } from './base';
|
||||
import querystring from 'querystring';
|
||||
|
||||
const BASE_COLLECTION = '/collection';
|
||||
|
||||
@@ -10,18 +9,23 @@ export class CollectionsEndpoint extends BaseEndpoint {
|
||||
}
|
||||
|
||||
async details(id: number, options? : LanguageOption): Promise<DetailedCollection> {
|
||||
const params = querystring.encode(options);
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<DetailedCollection>(`${BASE_COLLECTION}/${id}?${params}`);
|
||||
}
|
||||
|
||||
async images(id: number, options? : LanguageOption): Promise<ImageCollection> {
|
||||
const params = querystring.encode(options);
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<ImageCollection>(`${BASE_COLLECTION}/${id}/images?${params}`);
|
||||
}
|
||||
|
||||
async translations(id: number, options? : LanguageOption): Promise<Translations> {
|
||||
const params = querystring.encode(options);
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<Translations>(`${BASE_COLLECTION}/${id}/translations?${params}`);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BaseEndpoint } from './base';
|
||||
import querystring from 'querystring';
|
||||
import { BelongingMovies, Keyword, KeywordsOptions } from '../types';
|
||||
|
||||
const BASE_Keyword = '/keyword';
|
||||
@@ -14,7 +13,9 @@ export class KeywordsEndpoint extends BaseEndpoint {
|
||||
}
|
||||
|
||||
async belongingMovies(keywordId : number, options?: KeywordsOptions): Promise<BelongingMovies> {
|
||||
const params = querystring.encode(options);
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<BelongingMovies>(`${BASE_Keyword}/${keywordId}/movies?${params}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ export class PeopleEndpoint extends BaseEndpoint {
|
||||
}
|
||||
|
||||
async changes(id: number, options? : ChangeOptions): Promise<PersonChanges> {
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<PersonChanges>(`${BASE_PERSON}/${id}/changes?${params}`);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ export class PeopleEndpoint extends BaseEndpoint {
|
||||
}
|
||||
|
||||
async taggedImages(id: number, options?: PageOptions): Promise<TaggedImages>{
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<TaggedImages>(`${BASE_PERSON}/${id}/tagged_images?${params}`);
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ export class PeopleEndpoint extends BaseEndpoint {
|
||||
}
|
||||
|
||||
async popular(options?: PageOptions): Promise<PopularPersons>{
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<PopularPersons>(`${BASE_PERSON}/popular?${params}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ export class TvShowsEndpoint extends BaseEndpoint{
|
||||
}
|
||||
|
||||
async changes(id: number, options?: ChangeOptions): Promise<TvShowChanges>{
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<TvShowChanges>(`${BASE_TV}/${id}/changes?${params}`);
|
||||
}
|
||||
|
||||
@@ -78,16 +78,16 @@ export class TvShowsEndpoint extends BaseEndpoint{
|
||||
}
|
||||
|
||||
async recommendations(id: number, options?: PageOptions): Promise<Recommendations>{
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<Recommendations>(`${BASE_TV}/${id}/recommendations?${params}`);
|
||||
}
|
||||
|
||||
async reviews(id: number, options?: PageOptions): Promise<Reviews>{
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<Reviews>(`${BASE_TV}/${id}/reviews?${params}`);
|
||||
}
|
||||
|
||||
@@ -96,9 +96,9 @@ export class TvShowsEndpoint extends BaseEndpoint{
|
||||
}
|
||||
|
||||
async similar(id: number, options?: PageOptions): Promise<SimilarTvShows>{
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<SimilarTvShows>(`${BASE_TV}/${id}/similar?${params}`);
|
||||
}
|
||||
|
||||
@@ -127,23 +127,23 @@ export class TvShowsEndpoint extends BaseEndpoint{
|
||||
}
|
||||
|
||||
async airingToday(options?: LocaleOptions): Promise<TvShowsAiringToday>{
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<TvShowsAiringToday>(`${BASE_TV}/airing_today?${params}`);
|
||||
}
|
||||
|
||||
async popular(options?: PageOptions): Promise<PopularTvShows>{
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<PopularTvShows>(`${BASE_TV}/popular?${params}`);
|
||||
}
|
||||
|
||||
async topRated(options?: LocaleOptions): Promise<TopRatedTvShows>{
|
||||
const params = options == undefined
|
||||
? undefined
|
||||
: new URLSearchParams(Object.entries(options)).toString();
|
||||
const params = options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
: '';
|
||||
return await this.api.get<TopRatedTvShows>(`${BASE_TV}/top_rated?${params}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ParsedUrlQueryInput } from 'querystring';
|
||||
import { Movie } from '.';
|
||||
|
||||
export interface KeywordsOptions extends ParsedUrlQueryInput {
|
||||
export interface KeywordsOptions {
|
||||
include_adult?: boolean;
|
||||
language?: string;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { ParsedUrlQueryInput } from 'querystring';
|
||||
|
||||
export interface LanguageOption extends ParsedUrlQueryInput {
|
||||
language?: string;
|
||||
export interface LanguageOption {
|
||||
language?: string;
|
||||
}
|
||||
|
||||
export interface PageOption extends ParsedUrlQueryInput {
|
||||
page?: number;
|
||||
export interface PageOption {
|
||||
page?: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user