feat: introduce new report "Top Albums"

This commit is contained in:
Julian Tölle 2020-11-15 02:43:23 +01:00
parent 09858076bf
commit 9896ea31ff
16 changed files with 246 additions and 9 deletions

View file

@ -5,6 +5,8 @@ import { ListenReportItem } from "./entities/listen-report-item";
import { ListenReportOptions } from "./entities/listen-report-options";
import { Pagination } from "./entities/pagination";
import { PaginationOptions } from "./entities/pagination-options";
import { TopAlbumsItem } from "./entities/top-albums-item";
import { TopAlbumsOptions } from "./entities/top-albums-options";
import { TopArtistsItem } from "./entities/top-artists-item";
import { TopArtistsOptions } from "./entities/top-artists-options";
@ -110,3 +112,40 @@ export const getTopArtists = async (
} = res;
return items;
};
export const getTopAlbums = async (
options: TopAlbumsOptions,
client: AxiosInstance
): Promise<TopAlbumsItem[]> => {
const {
time: { timePreset, customTimeStart, customTimeEnd },
} = options;
const res = await client.get<{ items: TopAlbumsItem[] }>(
`/api/v1/reports/top-albums`,
{
params: {
timePreset,
customTimeStart: formatISO(customTimeStart),
customTimeEnd: formatISO(customTimeEnd),
},
}
);
switch (res.status) {
case 200: {
break;
}
case 401: {
throw new UnauthenticatedError(`No token or token expired`);
}
default: {
throw new Error(`Unable to getTopAlbums: ${res.status}`);
}
}
const {
data: { items },
} = res;
return items;
};

View file

@ -1,7 +1,9 @@
import { Artist } from "./artist";
import { SpotifyInfo } from "./spotify-info";
export interface Album {
id: string;
name: string;
spotify?: SpotifyInfo;
artists?: Artist[];
}

View file

@ -0,0 +1,6 @@
import { Album } from "./album";
export interface TopAlbumsItem {
album: Album;
count: number;
}

View file

@ -0,0 +1,5 @@
import { TimeOptions } from "./time-options";
export interface TopAlbumsOptions {
time: TimeOptions;
}

View file

@ -1,4 +1,3 @@
import { TimePreset } from "./time-preset.enum";
import { TimeOptions } from "./time-options";
export interface TopArtistsOptions {