386 lines
8.8 KiB
TypeScript
386 lines
8.8 KiB
TypeScript
/* eslint-disable */
|
|
/* tslint:disable */
|
|
// @ts-nocheck
|
|
/*
|
|
* ---------------------------------------------------------------
|
|
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
* ## ##
|
|
* ## AUTHOR: acacode ##
|
|
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
* ---------------------------------------------------------------
|
|
*/
|
|
|
|
export interface Item {
|
|
id?: number;
|
|
value?: string;
|
|
}
|
|
|
|
export interface PaginatedItems {
|
|
data?: Item[];
|
|
total?: number;
|
|
page?: number;
|
|
limit?: number;
|
|
hasMore?: boolean;
|
|
}
|
|
|
|
import type {
|
|
AxiosInstance,
|
|
AxiosRequestConfig,
|
|
HeadersDefaults,
|
|
ResponseType,
|
|
} from "axios";
|
|
import axios from "axios";
|
|
|
|
export type QueryParamsType = Record<string | number, any>;
|
|
|
|
export interface FullRequestParams
|
|
extends Omit<AxiosRequestConfig, "data" | "params" | "url" | "responseType"> {
|
|
/** set parameter to `true` for call `securityWorker` for this request */
|
|
secure?: boolean;
|
|
/** request path */
|
|
path: string;
|
|
/** content type of request body */
|
|
type?: ContentType;
|
|
/** query params */
|
|
query?: QueryParamsType;
|
|
/** format of response (i.e. response.json() -> format: "json") */
|
|
format?: ResponseType;
|
|
/** request body */
|
|
body?: unknown;
|
|
}
|
|
|
|
export type RequestParams = Omit<
|
|
FullRequestParams,
|
|
"body" | "method" | "query" | "path"
|
|
>;
|
|
|
|
export interface ApiConfig<SecurityDataType = unknown>
|
|
extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
|
|
securityWorker?: (
|
|
securityData: SecurityDataType | null,
|
|
) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
|
|
secure?: boolean;
|
|
format?: ResponseType;
|
|
}
|
|
|
|
export enum ContentType {
|
|
Json = "application/json",
|
|
JsonApi = "application/vnd.api+json",
|
|
FormData = "multipart/form-data",
|
|
UrlEncoded = "application/x-www-form-urlencoded",
|
|
Text = "text/plain",
|
|
}
|
|
|
|
export class HttpClient<SecurityDataType = unknown> {
|
|
public instance: AxiosInstance;
|
|
private securityData: SecurityDataType | null = null;
|
|
private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"];
|
|
private secure?: boolean;
|
|
private format?: ResponseType;
|
|
|
|
constructor({
|
|
securityWorker,
|
|
secure,
|
|
format,
|
|
...axiosConfig
|
|
}: ApiConfig<SecurityDataType> = {}) {
|
|
this.instance = axios.create({
|
|
...axiosConfig,
|
|
baseURL: axiosConfig.baseURL || "http://localhost:1337",
|
|
});
|
|
this.secure = secure;
|
|
this.format = format;
|
|
this.securityWorker = securityWorker;
|
|
}
|
|
|
|
public setSecurityData = (data: SecurityDataType | null) => {
|
|
this.securityData = data;
|
|
};
|
|
|
|
protected mergeRequestParams(
|
|
params1: AxiosRequestConfig,
|
|
params2?: AxiosRequestConfig,
|
|
): AxiosRequestConfig {
|
|
const method = params1.method || (params2 && params2.method);
|
|
|
|
return {
|
|
...this.instance.defaults,
|
|
...params1,
|
|
...(params2 || {}),
|
|
headers: {
|
|
...((method &&
|
|
this.instance.defaults.headers[
|
|
method.toLowerCase() as keyof HeadersDefaults
|
|
]) ||
|
|
{}),
|
|
...(params1.headers || {}),
|
|
...((params2 && params2.headers) || {}),
|
|
},
|
|
};
|
|
}
|
|
|
|
protected stringifyFormItem(formItem: unknown) {
|
|
if (typeof formItem === "object" && formItem !== null) {
|
|
return JSON.stringify(formItem);
|
|
} else {
|
|
return `${formItem}`;
|
|
}
|
|
}
|
|
|
|
protected createFormData(input: Record<string, unknown>): FormData {
|
|
if (input instanceof FormData) {
|
|
return input;
|
|
}
|
|
return Object.keys(input || {}).reduce((formData, key) => {
|
|
const property = input[key];
|
|
const propertyContent: any[] =
|
|
property instanceof Array ? property : [property];
|
|
|
|
for (const formItem of propertyContent) {
|
|
const isFileType = formItem instanceof Blob || formItem instanceof File;
|
|
formData.append(
|
|
key,
|
|
isFileType ? formItem : this.stringifyFormItem(formItem),
|
|
);
|
|
}
|
|
|
|
return formData;
|
|
}, new FormData());
|
|
}
|
|
|
|
public request = async <T = any, _E = any>({
|
|
secure,
|
|
path,
|
|
type,
|
|
query,
|
|
format,
|
|
body,
|
|
...params
|
|
}: FullRequestParams): Promise<T> => {
|
|
const secureParams =
|
|
((typeof secure === "boolean" ? secure : this.secure) &&
|
|
this.securityWorker &&
|
|
(await this.securityWorker(this.securityData))) ||
|
|
{};
|
|
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
const responseFormat = format || this.format || undefined;
|
|
|
|
if (
|
|
type === ContentType.FormData &&
|
|
body &&
|
|
body !== null &&
|
|
typeof body === "object"
|
|
) {
|
|
body = this.createFormData(body as Record<string, unknown>);
|
|
}
|
|
|
|
if (
|
|
type === ContentType.Text &&
|
|
body &&
|
|
body !== null &&
|
|
typeof body !== "string"
|
|
) {
|
|
body = JSON.stringify(body);
|
|
}
|
|
|
|
return this.instance
|
|
.request({
|
|
...requestParams,
|
|
headers: {
|
|
...(requestParams.headers || {}),
|
|
...(type ? { "Content-Type": type } : {}),
|
|
},
|
|
params: query,
|
|
responseType: responseFormat,
|
|
data: body,
|
|
url: path,
|
|
})
|
|
.then((response) => response.data);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @title TMC Items API
|
|
* @version 1.0.0
|
|
* @baseUrl http://localhost:1337
|
|
*
|
|
* API for managing items with selection and ordering
|
|
*/
|
|
export class Api<
|
|
SecurityDataType extends unknown,
|
|
> extends HttpClient<SecurityDataType> {
|
|
api = {
|
|
/**
|
|
* No description
|
|
*
|
|
* @tags Items
|
|
* @name ItemsList
|
|
* @summary Get unselected items
|
|
* @request GET:/api/items
|
|
*/
|
|
itemsList: (
|
|
query?: {
|
|
/** @default 1 */
|
|
page?: number;
|
|
/**
|
|
* @max 20
|
|
* @default 20
|
|
*/
|
|
limit?: number;
|
|
search?: string;
|
|
},
|
|
params: RequestParams = {},
|
|
) =>
|
|
this.request<PaginatedItems, any>({
|
|
path: `/api/items`,
|
|
method: "GET",
|
|
query: query,
|
|
format: "json",
|
|
...params,
|
|
}),
|
|
|
|
/**
|
|
* No description
|
|
*
|
|
* @tags Items
|
|
* @name ItemsSelectedList
|
|
* @summary Get selected items in order
|
|
* @request GET:/api/items/selected
|
|
*/
|
|
itemsSelectedList: (
|
|
query?: {
|
|
/** @default 1 */
|
|
page?: number;
|
|
/**
|
|
* @max 20
|
|
* @default 20
|
|
*/
|
|
limit?: number;
|
|
search?: string;
|
|
},
|
|
params: RequestParams = {},
|
|
) =>
|
|
this.request<PaginatedItems, any>({
|
|
path: `/api/items/selected`,
|
|
method: "GET",
|
|
query: query,
|
|
format: "json",
|
|
...params,
|
|
}),
|
|
|
|
/**
|
|
* No description
|
|
*
|
|
* @tags Items
|
|
* @name ItemsAddCreate
|
|
* @summary Queue an item for addition
|
|
* @request POST:/api/items/add
|
|
*/
|
|
itemsAddCreate: (
|
|
data: {
|
|
id: number;
|
|
},
|
|
params: RequestParams = {},
|
|
) =>
|
|
this.request<
|
|
{
|
|
queued?: boolean;
|
|
id?: number;
|
|
},
|
|
void
|
|
>({
|
|
path: `/api/items/add`,
|
|
method: "POST",
|
|
body: data,
|
|
type: ContentType.Json,
|
|
format: "json",
|
|
...params,
|
|
}),
|
|
|
|
/**
|
|
* No description
|
|
*
|
|
* @tags Items
|
|
* @name ItemsSelectCreate
|
|
* @summary Queue an item for selection (move to right panel)
|
|
* @request POST:/api/items/select
|
|
*/
|
|
itemsSelectCreate: (
|
|
data: {
|
|
id: number;
|
|
},
|
|
params: RequestParams = {},
|
|
) =>
|
|
this.request<
|
|
{
|
|
queued?: boolean;
|
|
},
|
|
any
|
|
>({
|
|
path: `/api/items/select`,
|
|
method: "POST",
|
|
body: data,
|
|
type: ContentType.Json,
|
|
format: "json",
|
|
...params,
|
|
}),
|
|
|
|
/**
|
|
* No description
|
|
*
|
|
* @tags Items
|
|
* @name ItemsDeselectCreate
|
|
* @summary Queue an item for deselection (move back to left panel)
|
|
* @request POST:/api/items/deselect
|
|
*/
|
|
itemsDeselectCreate: (
|
|
data: {
|
|
id: number;
|
|
},
|
|
params: RequestParams = {},
|
|
) =>
|
|
this.request<
|
|
{
|
|
queued?: boolean;
|
|
},
|
|
any
|
|
>({
|
|
path: `/api/items/deselect`,
|
|
method: "POST",
|
|
body: data,
|
|
type: ContentType.Json,
|
|
format: "json",
|
|
...params,
|
|
}),
|
|
|
|
/**
|
|
* No description
|
|
*
|
|
* @tags Items
|
|
* @name ItemsReorderUpdate
|
|
* @summary Move a selected item after another item (works with filtered lists)
|
|
* @request PUT:/api/items/reorder
|
|
*/
|
|
itemsReorderUpdate: (
|
|
data: {
|
|
id: number;
|
|
afterId: number | null;
|
|
},
|
|
params: RequestParams = {},
|
|
) =>
|
|
this.request<
|
|
{
|
|
queued?: boolean;
|
|
},
|
|
any
|
|
>({
|
|
path: `/api/items/reorder`,
|
|
method: "PUT",
|
|
body: data,
|
|
type: ContentType.Json,
|
|
format: "json",
|
|
...params,
|
|
}),
|
|
};
|
|
}
|