Switched to the <field>-<dir> notation in orderBy param for short URLs list

This commit is contained in:
Alejandro Celaya
2021-12-14 23:01:19 +01:00
parent 654b36ab08
commit 17e4e06fcc
4 changed files with 41 additions and 3 deletions

View File

@@ -16,11 +16,26 @@ import {
ShlinkEditDomainRedirects,
ShlinkDomainRedirects,
ShlinkShortUrlsListParams,
ShlinkShortUrlsListNormalizedParams,
} from '../types';
import { stringifyQuery } from '../../utils/helpers/query';
const buildShlinkBaseUrl = (url: string, apiVersion: number) => url ? `${url}/rest/v${apiVersion}` : '';
const rejectNilProps = reject(isNil);
const normalizeOrderByInParams = (params: ShlinkShortUrlsListParams): ShlinkShortUrlsListNormalizedParams => {
if (!params.orderBy) {
return params as ShlinkShortUrlsListNormalizedParams;
}
const { orderBy, ...rest } = params;
const [ firstKey ] = Object.keys(orderBy);
const [ firstValue ] = Object.values(orderBy);
return !firstValue ? rest : {
...rest,
orderBy: `${firstKey}-${firstValue}`,
};
};
export default class ShlinkApiClient {
private apiVersion: number;
@@ -34,7 +49,7 @@ export default class ShlinkApiClient {
}
public readonly listShortUrls = async (params: ShlinkShortUrlsListParams = {}): Promise<ShlinkShortUrlsResponse> =>
this.performRequest<{ shortUrls: ShlinkShortUrlsResponse }>('/short-urls', 'GET', params)
this.performRequest<{ shortUrls: ShlinkShortUrlsResponse }>('/short-urls', 'GET', normalizeOrderByInParams(params))
.then(({ data }) => data.shortUrls);
public readonly createShortUrl = async (options: ShortUrlData): Promise<ShortUrl> => {

View File

@@ -97,6 +97,10 @@ export interface ShlinkShortUrlsListParams {
orderBy?: OrderBy;
}
export interface ShlinkShortUrlsListNormalizedParams extends Omit<ShlinkShortUrlsListParams, 'orderBy'> {
orderBy?: string;
}
export interface ProblemDetailsError {
type: string;
detail: string;