Split tagsList and tagsStats methods in ShlinkApiClient for clarity

This commit is contained in:
Alejandro Celaya
2023-03-18 16:32:04 +01:00
parent a9af5163c1
commit 96c20b36a5
3 changed files with 18 additions and 13 deletions

View File

@@ -86,14 +86,15 @@ export class ShlinkApiClient {
): Promise<ShortUrl> =>
this.performRequest<ShortUrl>(`/short-urls/${shortCode}`, 'PATCH', { domain }, edit);
public readonly listTags = async (useTagsStatsEndpoint: boolean): Promise<ShlinkTags> =>
(useTagsStatsEndpoint
? this.performRequest<{ tags: ShlinkTagsStatsResponse }>('/tags/stats', 'GET')
.then(({ tags }) => tags)
.then(({ data }) => ({ tags: data.map(({ tag }) => tag), stats: data }))
: this.performRequest<{ tags: ShlinkTagsResponse }>('/tags', 'GET', { withStats: 'true' })
.then(({ tags }) => tags)
.then(({ data, stats }) => ({ tags: data, stats })));
public readonly listTags = async (): Promise<ShlinkTags> =>
this.performRequest<{ tags: ShlinkTagsResponse }>('/tags', 'GET', { withStats: 'true' })
.then(({ tags }) => tags)
.then(({ data, stats }) => ({ tags: data, stats }));
public readonly tagsStats = async (): Promise<ShlinkTags> =>
this.performRequest<{ tags: ShlinkTagsStatsResponse }>('/tags/stats', 'GET')
.then(({ tags }) => tags)
.then(({ data }) => ({ tags: data.map(({ tag }) => tag), stats: data }));
public readonly deleteTags = async (tags: string[]): Promise<{ tags: string[] }> =>
this.performEmptyRequest('/tags', 'DELETE', { tags }).then(() => ({ tags }));