-
Notifications
You must be signed in to change notification settings - Fork 13
/
SearchManager.ts
31 lines (25 loc) · 1.06 KB
/
SearchManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { SearchItems, SearchOptions } from '../../interfaces/Spotify';
import { Manager } from '../Manager';
export class SearchManager extends Manager {
/**
* @description Search the Spotify catalog for anything that matches the searchQuery.
* @param {string} searchQuery The query you want to search for.
* @param {SearchOptions} options The search options.
* @returns {Promise<SearchItems>} Returns a promise with all the {@link SearchItems}.
*/
async get(searchQuery: string, options: SearchOptions): Promise<SearchItems> {
const types = Object.keys(options.include).filter((key) => options.include[key]);
const query: Record<string, string> = {
q: searchQuery,
limit: options?.limit?.toString() || '20',
offset: options?.offset?.toString() || '0',
type: types.join(',')
};
if (options?.market) query.market = options.market;
if (options?.includeExternal) query.include_external = options.includeExternal;
const res = await this.http.get('/search', {
query
});
return res.data as SearchItems;
}
}