mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-23 16:13:50 +00:00
Fix of errors: automatic and some manual
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import {Scope} from '../../types';
|
||||
|
||||
export type body = {[key: string]: boolean|string|number|null};
|
||||
export type fetchOption = {[key: string]: boolean|string|number|null};
|
||||
export type body = Record<string, boolean|string|number|null>;
|
||||
export type fetchOption = Record<string, boolean|string|number|null>;
|
||||
|
||||
export interface Params {
|
||||
[key: string]: number|string
|
||||
}
|
||||
export type Params = Record<string, number|string>;
|
||||
|
||||
export interface PaginationResponse<T> {
|
||||
pagination: {
|
||||
@@ -16,9 +14,7 @@ export interface PaginationResponse<T> {
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface FetchParams {
|
||||
[K: string]: string|number|null;
|
||||
};
|
||||
export type FetchParams = Record<string, string|number|null>;;
|
||||
|
||||
export interface TransportExceptionInterface {
|
||||
name: string;
|
||||
@@ -118,15 +114,15 @@ export const makeFetch = <Input, Output>(
|
||||
* Fetch results with certain parameters
|
||||
*/
|
||||
function _fetchAction<T>(page: number, uri: string, params?: FetchParams): Promise<PaginationResponse<T>> {
|
||||
const item_per_page: number = 50;
|
||||
const item_per_page = 50;
|
||||
|
||||
let searchParams = new URLSearchParams();
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.append('item_per_page', item_per_page.toString());
|
||||
searchParams.append('page', page.toString());
|
||||
|
||||
if (params !== undefined) {
|
||||
Object.keys(params).forEach(key => {
|
||||
let v = params[key];
|
||||
const v = params[key];
|
||||
if (typeof v === 'string') {
|
||||
searchParams.append(key, v);
|
||||
} else if (typeof v === 'number') {
|
||||
@@ -137,7 +133,7 @@ function _fetchAction<T>(page: number, uri: string, params?: FetchParams): Promi
|
||||
});
|
||||
}
|
||||
|
||||
let url = uri + '?' + searchParams.toString();
|
||||
const url = uri + '?' + searchParams.toString();
|
||||
|
||||
return fetch(url, {
|
||||
method: 'GET',
|
||||
@@ -177,7 +173,7 @@ function _fetchAction<T>(page: number, uri: string, params?: FetchParams): Promi
|
||||
export const fetchResults = async<T> (uri: string, params?: FetchParams): Promise<T[]> => {
|
||||
let promises: Promise<T[]>[] = [],
|
||||
page = 1;
|
||||
let firstData: PaginationResponse<T> = await _fetchAction(page, uri, params) as PaginationResponse<T>;
|
||||
const firstData: PaginationResponse<T> = await _fetchAction(page, uri, params) as PaginationResponse<T>;
|
||||
|
||||
promises.push(Promise.resolve(firstData.results));
|
||||
|
||||
|
Reference in New Issue
Block a user