mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 12:16:36 +00:00
Switched to the <field>-<dir> notation in orderBy param for short URLs list
This commit is contained in:
@@ -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> => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user