moved option parsing in superclass 'get' method

This commit is contained in:
DerPenz
2023-04-14 15:54:27 +02:00
parent 7cccdb9929
commit 1200064194
2 changed files with 5 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import fetch from 'cross-fetch';
import { parseOptions } from './utils';
const BASE_URL_V3 = 'https://api.themoviedb.org/3';
@@ -7,8 +8,9 @@ export default class Api {
this.accessToken = accessToken;
}
async get<T>(path: string): Promise<T> {
const response = await fetch(`${BASE_URL_V3}${path}`, {
async get<T>(path: string, options?: Record<string,any>): Promise<T> {
const params = parseOptions(options);
const response = await fetch(`${BASE_URL_V3}${path}?${params}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${this.accessToken}`,

View File

@@ -1,5 +1,5 @@
export function parseOptions(
options?: { [s: string]: any },
options?: Record<string, any>,
): string {
return options
? new URLSearchParams(Object.entries(options)).toString()