2653 lines
73 KiB
TypeScript
2653 lines
73 KiB
TypeScript
/**
|
|
* Generated by orval v8.9.1 🍺
|
|
* Do not edit manually.
|
|
* Api
|
|
* ToolRate API — Tool listing and rating platform
|
|
* OpenAPI spec version: 0.1.0
|
|
*/
|
|
import {
|
|
useMutation,
|
|
useQuery
|
|
} from '@tanstack/react-query';
|
|
import type {
|
|
MutationFunction,
|
|
QueryFunction,
|
|
QueryKey,
|
|
UseMutationOptions,
|
|
UseMutationResult,
|
|
UseQueryOptions,
|
|
UseQueryResult
|
|
} from '@tanstack/react-query';
|
|
|
|
import type {
|
|
AnalyticsSummary,
|
|
AuditLog,
|
|
AuthMode,
|
|
AuthUser,
|
|
CategoryStats,
|
|
EmptyTrash200,
|
|
ErrorResponse,
|
|
GetRatingDistributionParams,
|
|
GetTopToolsParams,
|
|
HealthStatus,
|
|
ListAuditLogsParams,
|
|
ListCompareToolsParams,
|
|
ListToolsParams,
|
|
ListTrashedToolsParams,
|
|
LocalLoginInput,
|
|
Rating,
|
|
RatingDistribution,
|
|
RatingHistoryItem,
|
|
RatingInput,
|
|
RestoreTools200,
|
|
Tool,
|
|
ToolInput,
|
|
ToolUpdate,
|
|
ToolWithStats,
|
|
TopToolEntry,
|
|
TrashTools200,
|
|
TrashToolsInput,
|
|
User,
|
|
UserCreateInput,
|
|
UserPreferences,
|
|
UserRoleUpdate,
|
|
VersionInfo
|
|
} from './api.schemas';
|
|
|
|
import { customFetch } from '../custom-fetch';
|
|
import type { ErrorType , BodyType } from '../custom-fetch';
|
|
|
|
type AwaitedInput<T> = PromiseLike<T> | T;
|
|
|
|
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
|
|
|
|
|
|
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
|
|
|
|
|
|
|
export const getHealthCheckUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/healthz`
|
|
}
|
|
|
|
/**
|
|
* Returns server health status
|
|
* @summary Health check
|
|
*/
|
|
export const healthCheck = async ( options?: RequestInit): Promise<HealthStatus> => {
|
|
|
|
return customFetch<HealthStatus>(getHealthCheckUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getHealthCheckQueryKey = () => {
|
|
return [
|
|
`/api/healthz`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getHealthCheckQueryOptions = <TData = Awaited<ReturnType<typeof healthCheck>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof healthCheck>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getHealthCheckQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof healthCheck>>> = ({ signal }) => healthCheck({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof healthCheck>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type HealthCheckQueryResult = NonNullable<Awaited<ReturnType<typeof healthCheck>>>
|
|
export type HealthCheckQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Health check
|
|
*/
|
|
|
|
export function useHealthCheck<TData = Awaited<ReturnType<typeof healthCheck>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof healthCheck>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getHealthCheckQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetVersionUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/version`
|
|
}
|
|
|
|
/**
|
|
* Returns the running build version, commit SHA and build date
|
|
* @summary Build version information
|
|
*/
|
|
export const getVersion = async ( options?: RequestInit): Promise<VersionInfo> => {
|
|
|
|
return customFetch<VersionInfo>(getGetVersionUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetVersionQueryKey = () => {
|
|
return [
|
|
`/api/version`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetVersionQueryOptions = <TData = Awaited<ReturnType<typeof getVersion>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getVersion>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetVersionQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getVersion>>> = ({ signal }) => getVersion({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getVersion>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetVersionQueryResult = NonNullable<Awaited<ReturnType<typeof getVersion>>>
|
|
export type GetVersionQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Build version information
|
|
*/
|
|
|
|
export function useGetVersion<TData = Awaited<ReturnType<typeof getVersion>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getVersion>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetVersionQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListToolsUrl = (params?: ListToolsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : value.toString())
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/tools?${stringifiedParams}` : `/api/tools`
|
|
}
|
|
|
|
/**
|
|
* @summary List all tools
|
|
*/
|
|
export const listTools = async (params?: ListToolsParams, options?: RequestInit): Promise<ToolWithStats[]> => {
|
|
|
|
return customFetch<ToolWithStats[]>(getListToolsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListToolsQueryKey = (params?: ListToolsParams,) => {
|
|
return [
|
|
`/api/tools`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListToolsQueryOptions = <TData = Awaited<ReturnType<typeof listTools>>, TError = ErrorType<unknown>>(params?: ListToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListToolsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listTools>>> = ({ signal }) => listTools(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listTools>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListToolsQueryResult = NonNullable<Awaited<ReturnType<typeof listTools>>>
|
|
export type ListToolsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List all tools
|
|
*/
|
|
|
|
export function useListTools<TData = Awaited<ReturnType<typeof listTools>>, TError = ErrorType<unknown>>(
|
|
params?: ListToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListToolsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateToolUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools`
|
|
}
|
|
|
|
/**
|
|
* @summary Create a new tool
|
|
*/
|
|
export const createTool = async (toolInput: ToolInput, options?: RequestInit): Promise<Tool> => {
|
|
|
|
return customFetch<Tool>(getCreateToolUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
toolInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getCreateToolMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createTool>>, TError,{data: BodyType<ToolInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof createTool>>, TError,{data: BodyType<ToolInput>}, TContext> => {
|
|
|
|
const mutationKey = ['createTool'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createTool>>, {data: BodyType<ToolInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return createTool(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type CreateToolMutationResult = NonNullable<Awaited<ReturnType<typeof createTool>>>
|
|
export type CreateToolMutationBody = BodyType<ToolInput>
|
|
export type CreateToolMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Create a new tool
|
|
*/
|
|
export const useCreateTool = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createTool>>, TError,{data: BodyType<ToolInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof createTool>>,
|
|
TError,
|
|
{data: BodyType<ToolInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getCreateToolMutationOptions(options));
|
|
}
|
|
|
|
export const getListCompareToolsUrl = (params: ListCompareToolsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : value.toString())
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/compare?${stringifiedParams}` : `/api/compare`
|
|
}
|
|
|
|
/**
|
|
* @summary Compare tools side by side (premium)
|
|
*/
|
|
export const listCompareTools = async (params: ListCompareToolsParams, options?: RequestInit): Promise<ToolWithStats[]> => {
|
|
|
|
return customFetch<ToolWithStats[]>(getListCompareToolsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListCompareToolsQueryKey = (params?: ListCompareToolsParams,) => {
|
|
return [
|
|
`/api/compare`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListCompareToolsQueryOptions = <TData = Awaited<ReturnType<typeof listCompareTools>>, TError = ErrorType<ErrorResponse>>(params: ListCompareToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listCompareTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListCompareToolsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listCompareTools>>> = ({ signal }) => listCompareTools(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listCompareTools>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListCompareToolsQueryResult = NonNullable<Awaited<ReturnType<typeof listCompareTools>>>
|
|
export type ListCompareToolsQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Compare tools side by side (premium)
|
|
*/
|
|
|
|
export function useListCompareTools<TData = Awaited<ReturnType<typeof listCompareTools>>, TError = ErrorType<ErrorResponse>>(
|
|
params: ListCompareToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listCompareTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListCompareToolsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetToolRatingHistoryUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}/rating-history`
|
|
}
|
|
|
|
/**
|
|
* @summary Get a tool's rating history over time
|
|
*/
|
|
export const getToolRatingHistory = async (id: number, options?: RequestInit): Promise<RatingHistoryItem[]> => {
|
|
|
|
return customFetch<RatingHistoryItem[]>(getGetToolRatingHistoryUrl(id),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetToolRatingHistoryQueryKey = (id: number,) => {
|
|
return [
|
|
`/api/tools/${id}/rating-history`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetToolRatingHistoryQueryOptions = <TData = Awaited<ReturnType<typeof getToolRatingHistory>>, TError = ErrorType<ErrorResponse>>(id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getToolRatingHistory>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetToolRatingHistoryQueryKey(id);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getToolRatingHistory>>> = ({ signal }) => getToolRatingHistory(id, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, enabled: !!(id), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getToolRatingHistory>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetToolRatingHistoryQueryResult = NonNullable<Awaited<ReturnType<typeof getToolRatingHistory>>>
|
|
export type GetToolRatingHistoryQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get a tool's rating history over time
|
|
*/
|
|
|
|
export function useGetToolRatingHistory<TData = Awaited<ReturnType<typeof getToolRatingHistory>>, TError = ErrorType<ErrorResponse>>(
|
|
id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getToolRatingHistory>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetToolRatingHistoryQueryOptions(id,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetToolUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Get a tool by ID
|
|
*/
|
|
export const getTool = async (id: number, options?: RequestInit): Promise<ToolWithStats> => {
|
|
|
|
return customFetch<ToolWithStats>(getGetToolUrl(id),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetToolQueryKey = (id: number,) => {
|
|
return [
|
|
`/api/tools/${id}`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetToolQueryOptions = <TData = Awaited<ReturnType<typeof getTool>>, TError = ErrorType<ErrorResponse>>(id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getTool>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetToolQueryKey(id);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getTool>>> = ({ signal }) => getTool(id, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, enabled: !!(id), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getTool>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetToolQueryResult = NonNullable<Awaited<ReturnType<typeof getTool>>>
|
|
export type GetToolQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get a tool by ID
|
|
*/
|
|
|
|
export function useGetTool<TData = Awaited<ReturnType<typeof getTool>>, TError = ErrorType<ErrorResponse>>(
|
|
id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getTool>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetToolQueryOptions(id,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getUpdateToolUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Update a tool
|
|
*/
|
|
export const updateTool = async (id: number,
|
|
toolUpdate: ToolUpdate, options?: RequestInit): Promise<Tool> => {
|
|
|
|
return customFetch<Tool>(getUpdateToolUrl(id),
|
|
{
|
|
...options,
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
toolUpdate,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getUpdateToolMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateTool>>, TError,{id: number;data: BodyType<ToolUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof updateTool>>, TError,{id: number;data: BodyType<ToolUpdate>}, TContext> => {
|
|
|
|
const mutationKey = ['updateTool'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateTool>>, {id: number;data: BodyType<ToolUpdate>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return updateTool(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type UpdateToolMutationResult = NonNullable<Awaited<ReturnType<typeof updateTool>>>
|
|
export type UpdateToolMutationBody = BodyType<ToolUpdate>
|
|
export type UpdateToolMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Update a tool
|
|
*/
|
|
export const useUpdateTool = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateTool>>, TError,{id: number;data: BodyType<ToolUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof updateTool>>,
|
|
TError,
|
|
{id: number;data: BodyType<ToolUpdate>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getUpdateToolMutationOptions(options));
|
|
}
|
|
|
|
export const getDeleteToolUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Delete a tool
|
|
*/
|
|
export const deleteTool = async (id: number, options?: RequestInit): Promise<void> => {
|
|
|
|
return customFetch<void>(getDeleteToolUrl(id),
|
|
{
|
|
...options,
|
|
method: 'DELETE'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getDeleteToolMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteTool>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof deleteTool>>, TError,{id: number}, TContext> => {
|
|
|
|
const mutationKey = ['deleteTool'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteTool>>, {id: number}> = (props) => {
|
|
const {id} = props ?? {};
|
|
|
|
return deleteTool(id,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type DeleteToolMutationResult = NonNullable<Awaited<ReturnType<typeof deleteTool>>>
|
|
|
|
export type DeleteToolMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Delete a tool
|
|
*/
|
|
export const useDeleteTool = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteTool>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof deleteTool>>,
|
|
TError,
|
|
{id: number},
|
|
TContext
|
|
> => {
|
|
return useMutation(getDeleteToolMutationOptions(options));
|
|
}
|
|
|
|
export const getListTrashedToolsUrl = (params?: ListTrashedToolsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : value.toString())
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/tools/trash?${stringifiedParams}` : `/api/tools/trash`
|
|
}
|
|
|
|
/**
|
|
* @summary List trashed (soft-deleted) tools
|
|
*/
|
|
export const listTrashedTools = async (params?: ListTrashedToolsParams, options?: RequestInit): Promise<Tool[]> => {
|
|
|
|
return customFetch<Tool[]>(getListTrashedToolsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListTrashedToolsQueryKey = (params?: ListTrashedToolsParams,) => {
|
|
return [
|
|
`/api/tools/trash`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListTrashedToolsQueryOptions = <TData = Awaited<ReturnType<typeof listTrashedTools>>, TError = ErrorType<ErrorResponse>>(params?: ListTrashedToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listTrashedTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListTrashedToolsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listTrashedTools>>> = ({ signal }) => listTrashedTools(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listTrashedTools>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListTrashedToolsQueryResult = NonNullable<Awaited<ReturnType<typeof listTrashedTools>>>
|
|
export type ListTrashedToolsQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary List trashed (soft-deleted) tools
|
|
*/
|
|
|
|
export function useListTrashedTools<TData = Awaited<ReturnType<typeof listTrashedTools>>, TError = ErrorType<ErrorResponse>>(
|
|
params?: ListTrashedToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listTrashedTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListTrashedToolsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getTrashToolsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/trash`
|
|
}
|
|
|
|
/**
|
|
* @summary Move tools to trash (admin)
|
|
*/
|
|
export const trashTools = async (trashToolsInput: TrashToolsInput, options?: RequestInit): Promise<TrashTools200> => {
|
|
|
|
return customFetch<TrashTools200>(getTrashToolsUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
trashToolsInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getTrashToolsMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof trashTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof trashTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext> => {
|
|
|
|
const mutationKey = ['trashTools'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof trashTools>>, {data: BodyType<TrashToolsInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return trashTools(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type TrashToolsMutationResult = NonNullable<Awaited<ReturnType<typeof trashTools>>>
|
|
export type TrashToolsMutationBody = BodyType<TrashToolsInput>
|
|
export type TrashToolsMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Move tools to trash (admin)
|
|
*/
|
|
export const useTrashTools = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof trashTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof trashTools>>,
|
|
TError,
|
|
{data: BodyType<TrashToolsInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getTrashToolsMutationOptions(options));
|
|
}
|
|
|
|
export const getDeleteTrashedToolsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/trash`
|
|
}
|
|
|
|
/**
|
|
* @summary Permanently delete trashed tools (admin)
|
|
*/
|
|
export const deleteTrashedTools = async (trashToolsInput: TrashToolsInput, options?: RequestInit): Promise<void> => {
|
|
|
|
return customFetch<void>(getDeleteTrashedToolsUrl(),
|
|
{
|
|
...options,
|
|
method: 'DELETE',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
trashToolsInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getDeleteTrashedToolsMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteTrashedTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof deleteTrashedTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext> => {
|
|
|
|
const mutationKey = ['deleteTrashedTools'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteTrashedTools>>, {data: BodyType<TrashToolsInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return deleteTrashedTools(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type DeleteTrashedToolsMutationResult = NonNullable<Awaited<ReturnType<typeof deleteTrashedTools>>>
|
|
export type DeleteTrashedToolsMutationBody = BodyType<TrashToolsInput>
|
|
export type DeleteTrashedToolsMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Permanently delete trashed tools (admin)
|
|
*/
|
|
export const useDeleteTrashedTools = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteTrashedTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof deleteTrashedTools>>,
|
|
TError,
|
|
{data: BodyType<TrashToolsInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getDeleteTrashedToolsMutationOptions(options));
|
|
}
|
|
|
|
export const getRestoreToolsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/trash/restore`
|
|
}
|
|
|
|
/**
|
|
* @summary Restore trashed tools
|
|
*/
|
|
export const restoreTools = async (trashToolsInput: TrashToolsInput, options?: RequestInit): Promise<RestoreTools200> => {
|
|
|
|
return customFetch<RestoreTools200>(getRestoreToolsUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
trashToolsInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getRestoreToolsMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof restoreTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof restoreTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext> => {
|
|
|
|
const mutationKey = ['restoreTools'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof restoreTools>>, {data: BodyType<TrashToolsInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return restoreTools(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type RestoreToolsMutationResult = NonNullable<Awaited<ReturnType<typeof restoreTools>>>
|
|
export type RestoreToolsMutationBody = BodyType<TrashToolsInput>
|
|
export type RestoreToolsMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Restore trashed tools
|
|
*/
|
|
export const useRestoreTools = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof restoreTools>>, TError,{data: BodyType<TrashToolsInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof restoreTools>>,
|
|
TError,
|
|
{data: BodyType<TrashToolsInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getRestoreToolsMutationOptions(options));
|
|
}
|
|
|
|
export const getEmptyTrashUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/trash/empty`
|
|
}
|
|
|
|
/**
|
|
* @summary Permanently delete all trashed tools (admin)
|
|
*/
|
|
export const emptyTrash = async ( options?: RequestInit): Promise<EmptyTrash200> => {
|
|
|
|
return customFetch<EmptyTrash200>(getEmptyTrashUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getEmptyTrashMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof emptyTrash>>, TError,void, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof emptyTrash>>, TError,void, TContext> => {
|
|
|
|
const mutationKey = ['emptyTrash'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof emptyTrash>>, void> = () => {
|
|
|
|
|
|
return emptyTrash(requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type EmptyTrashMutationResult = NonNullable<Awaited<ReturnType<typeof emptyTrash>>>
|
|
|
|
export type EmptyTrashMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Permanently delete all trashed tools (admin)
|
|
*/
|
|
export const useEmptyTrash = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof emptyTrash>>, TError,void, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof emptyTrash>>,
|
|
TError,
|
|
void,
|
|
TContext
|
|
> => {
|
|
return useMutation(getEmptyTrashMutationOptions(options));
|
|
}
|
|
|
|
export const getListToolRatingsUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}/ratings`
|
|
}
|
|
|
|
/**
|
|
* @summary List ratings for a tool
|
|
*/
|
|
export const listToolRatings = async (id: number, options?: RequestInit): Promise<Rating[]> => {
|
|
|
|
return customFetch<Rating[]>(getListToolRatingsUrl(id),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListToolRatingsQueryKey = (id: number,) => {
|
|
return [
|
|
`/api/tools/${id}/ratings`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListToolRatingsQueryOptions = <TData = Awaited<ReturnType<typeof listToolRatings>>, TError = ErrorType<unknown>>(id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listToolRatings>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListToolRatingsQueryKey(id);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listToolRatings>>> = ({ signal }) => listToolRatings(id, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, enabled: !!(id), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listToolRatings>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListToolRatingsQueryResult = NonNullable<Awaited<ReturnType<typeof listToolRatings>>>
|
|
export type ListToolRatingsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List ratings for a tool
|
|
*/
|
|
|
|
export function useListToolRatings<TData = Awaited<ReturnType<typeof listToolRatings>>, TError = ErrorType<unknown>>(
|
|
id: number, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listToolRatings>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListToolRatingsQueryOptions(id,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateRatingUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/tools/${id}/ratings`
|
|
}
|
|
|
|
/**
|
|
* @summary Submit a rating for a tool
|
|
*/
|
|
export const createRating = async (id: number,
|
|
ratingInput: RatingInput, options?: RequestInit): Promise<Rating> => {
|
|
|
|
return customFetch<Rating>(getCreateRatingUrl(id),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
ratingInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getCreateRatingMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createRating>>, TError,{id: number;data: BodyType<RatingInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof createRating>>, TError,{id: number;data: BodyType<RatingInput>}, TContext> => {
|
|
|
|
const mutationKey = ['createRating'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createRating>>, {id: number;data: BodyType<RatingInput>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return createRating(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type CreateRatingMutationResult = NonNullable<Awaited<ReturnType<typeof createRating>>>
|
|
export type CreateRatingMutationBody = BodyType<RatingInput>
|
|
export type CreateRatingMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Submit a rating for a tool
|
|
*/
|
|
export const useCreateRating = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createRating>>, TError,{id: number;data: BodyType<RatingInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof createRating>>,
|
|
TError,
|
|
{id: number;data: BodyType<RatingInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getCreateRatingMutationOptions(options));
|
|
}
|
|
|
|
export const getGetAnalyticsSummaryUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/analytics/summary`
|
|
}
|
|
|
|
/**
|
|
* @summary Overall platform statistics
|
|
*/
|
|
export const getAnalyticsSummary = async ( options?: RequestInit): Promise<AnalyticsSummary> => {
|
|
|
|
return customFetch<AnalyticsSummary>(getGetAnalyticsSummaryUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAnalyticsSummaryQueryKey = () => {
|
|
return [
|
|
`/api/analytics/summary`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetAnalyticsSummaryQueryOptions = <TData = Awaited<ReturnType<typeof getAnalyticsSummary>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsSummary>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetAnalyticsSummaryQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getAnalyticsSummary>>> = ({ signal }) => getAnalyticsSummary({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsSummary>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetAnalyticsSummaryQueryResult = NonNullable<Awaited<ReturnType<typeof getAnalyticsSummary>>>
|
|
export type GetAnalyticsSummaryQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Overall platform statistics
|
|
*/
|
|
|
|
export function useGetAnalyticsSummary<TData = Awaited<ReturnType<typeof getAnalyticsSummary>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsSummary>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetAnalyticsSummaryQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetTopToolsUrl = (params?: GetTopToolsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : value.toString())
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/analytics/top-tools?${stringifiedParams}` : `/api/analytics/top-tools`
|
|
}
|
|
|
|
/**
|
|
* @summary Top-rated tools
|
|
*/
|
|
export const getTopTools = async (params?: GetTopToolsParams, options?: RequestInit): Promise<TopToolEntry[]> => {
|
|
|
|
return customFetch<TopToolEntry[]>(getGetTopToolsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetTopToolsQueryKey = (params?: GetTopToolsParams,) => {
|
|
return [
|
|
`/api/analytics/top-tools`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetTopToolsQueryOptions = <TData = Awaited<ReturnType<typeof getTopTools>>, TError = ErrorType<unknown>>(params?: GetTopToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getTopTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetTopToolsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getTopTools>>> = ({ signal }) => getTopTools(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getTopTools>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetTopToolsQueryResult = NonNullable<Awaited<ReturnType<typeof getTopTools>>>
|
|
export type GetTopToolsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Top-rated tools
|
|
*/
|
|
|
|
export function useGetTopTools<TData = Awaited<ReturnType<typeof getTopTools>>, TError = ErrorType<unknown>>(
|
|
params?: GetTopToolsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getTopTools>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetTopToolsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAnalyticsByCategoryUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/analytics/by-category`
|
|
}
|
|
|
|
/**
|
|
* @summary Rating statistics grouped by category
|
|
*/
|
|
export const getAnalyticsByCategory = async ( options?: RequestInit): Promise<CategoryStats[]> => {
|
|
|
|
return customFetch<CategoryStats[]>(getGetAnalyticsByCategoryUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAnalyticsByCategoryQueryKey = () => {
|
|
return [
|
|
`/api/analytics/by-category`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetAnalyticsByCategoryQueryOptions = <TData = Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetAnalyticsByCategoryQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getAnalyticsByCategory>>> = ({ signal }) => getAnalyticsByCategory({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetAnalyticsByCategoryQueryResult = NonNullable<Awaited<ReturnType<typeof getAnalyticsByCategory>>>
|
|
export type GetAnalyticsByCategoryQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Rating statistics grouped by category
|
|
*/
|
|
|
|
export function useGetAnalyticsByCategory<TData = Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAnalyticsByCategory>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetAnalyticsByCategoryQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetRatingDistributionUrl = (params?: GetRatingDistributionParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : value.toString())
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/analytics/rating-distribution?${stringifiedParams}` : `/api/analytics/rating-distribution`
|
|
}
|
|
|
|
/**
|
|
* @summary Distribution of rating scores across the platform
|
|
*/
|
|
export const getRatingDistribution = async (params?: GetRatingDistributionParams, options?: RequestInit): Promise<RatingDistribution> => {
|
|
|
|
return customFetch<RatingDistribution>(getGetRatingDistributionUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetRatingDistributionQueryKey = (params?: GetRatingDistributionParams,) => {
|
|
return [
|
|
`/api/analytics/rating-distribution`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetRatingDistributionQueryOptions = <TData = Awaited<ReturnType<typeof getRatingDistribution>>, TError = ErrorType<unknown>>(params?: GetRatingDistributionParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getRatingDistribution>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetRatingDistributionQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getRatingDistribution>>> = ({ signal }) => getRatingDistribution(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getRatingDistribution>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetRatingDistributionQueryResult = NonNullable<Awaited<ReturnType<typeof getRatingDistribution>>>
|
|
export type GetRatingDistributionQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Distribution of rating scores across the platform
|
|
*/
|
|
|
|
export function useGetRatingDistribution<TData = Awaited<ReturnType<typeof getRatingDistribution>>, TError = ErrorType<unknown>>(
|
|
params?: GetRatingDistributionParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getRatingDistribution>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetRatingDistributionQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListCategoriesUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/categories`
|
|
}
|
|
|
|
/**
|
|
* @summary List all distinct tool categories
|
|
*/
|
|
export const listCategories = async ( options?: RequestInit): Promise<string[]> => {
|
|
|
|
return customFetch<string[]>(getListCategoriesUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListCategoriesQueryKey = () => {
|
|
return [
|
|
`/api/categories`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListCategoriesQueryOptions = <TData = Awaited<ReturnType<typeof listCategories>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listCategories>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListCategoriesQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listCategories>>> = ({ signal }) => listCategories({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listCategories>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListCategoriesQueryResult = NonNullable<Awaited<ReturnType<typeof listCategories>>>
|
|
export type ListCategoriesQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List all distinct tool categories
|
|
*/
|
|
|
|
export function useListCategories<TData = Awaited<ReturnType<typeof listCategories>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listCategories>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListCategoriesQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAllFeaturesUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/features/all`
|
|
}
|
|
|
|
/**
|
|
* @summary List all distinct feature strings across all tools
|
|
*/
|
|
export const listAllFeatures = async ( options?: RequestInit): Promise<string[]> => {
|
|
|
|
return customFetch<string[]>(getListAllFeaturesUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAllFeaturesQueryKey = () => {
|
|
return [
|
|
`/api/features/all`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListAllFeaturesQueryOptions = <TData = Awaited<ReturnType<typeof listAllFeatures>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAllFeatures>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListAllFeaturesQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listAllFeatures>>> = ({ signal }) => listAllFeatures({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listAllFeatures>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListAllFeaturesQueryResult = NonNullable<Awaited<ReturnType<typeof listAllFeatures>>>
|
|
export type ListAllFeaturesQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List all distinct feature strings across all tools
|
|
*/
|
|
|
|
export function useListAllFeatures<TData = Awaited<ReturnType<typeof listAllFeatures>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAllFeatures>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListAllFeaturesQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAllTagsUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/tags/all`
|
|
}
|
|
|
|
/**
|
|
* @summary List all distinct tag strings across all tools
|
|
*/
|
|
export const listAllTags = async ( options?: RequestInit): Promise<string[]> => {
|
|
|
|
return customFetch<string[]>(getListAllTagsUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAllTagsQueryKey = () => {
|
|
return [
|
|
`/api/tags/all`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListAllTagsQueryOptions = <TData = Awaited<ReturnType<typeof listAllTags>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAllTags>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListAllTagsQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listAllTags>>> = ({ signal }) => listAllTags({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listAllTags>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListAllTagsQueryResult = NonNullable<Awaited<ReturnType<typeof listAllTags>>>
|
|
export type ListAllTagsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List all distinct tag strings across all tools
|
|
*/
|
|
|
|
export function useListAllTags<TData = Awaited<ReturnType<typeof listAllTags>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAllTags>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListAllTagsQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAuthModeUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/mode`
|
|
}
|
|
|
|
/**
|
|
* @summary Get authentication mode (oidc or local)
|
|
*/
|
|
export const getAuthMode = async ( options?: RequestInit): Promise<AuthMode> => {
|
|
|
|
return customFetch<AuthMode>(getGetAuthModeUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetAuthModeQueryKey = () => {
|
|
return [
|
|
`/api/auth/mode`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetAuthModeQueryOptions = <TData = Awaited<ReturnType<typeof getAuthMode>>, TError = ErrorType<unknown>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAuthMode>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetAuthModeQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getAuthMode>>> = ({ signal }) => getAuthMode({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getAuthMode>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetAuthModeQueryResult = NonNullable<Awaited<ReturnType<typeof getAuthMode>>>
|
|
export type GetAuthModeQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary Get authentication mode (oidc or local)
|
|
*/
|
|
|
|
export function useGetAuthMode<TData = Awaited<ReturnType<typeof getAuthMode>>, TError = ErrorType<unknown>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getAuthMode>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetAuthModeQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getLocalLoginUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/login`
|
|
}
|
|
|
|
/**
|
|
* @summary Local username/password login
|
|
*/
|
|
export const localLogin = async (localLoginInput: LocalLoginInput, options?: RequestInit): Promise<AuthUser> => {
|
|
|
|
return customFetch<AuthUser>(getLocalLoginUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
localLoginInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getLocalLoginMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof localLogin>>, TError,{data: BodyType<LocalLoginInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof localLogin>>, TError,{data: BodyType<LocalLoginInput>}, TContext> => {
|
|
|
|
const mutationKey = ['localLogin'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof localLogin>>, {data: BodyType<LocalLoginInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return localLogin(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type LocalLoginMutationResult = NonNullable<Awaited<ReturnType<typeof localLogin>>>
|
|
export type LocalLoginMutationBody = BodyType<LocalLoginInput>
|
|
export type LocalLoginMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Local username/password login
|
|
*/
|
|
export const useLocalLogin = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof localLogin>>, TError,{data: BodyType<LocalLoginInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof localLogin>>,
|
|
TError,
|
|
{data: BodyType<LocalLoginInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getLocalLoginMutationOptions(options));
|
|
}
|
|
|
|
export const getGetMeUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/me`
|
|
}
|
|
|
|
/**
|
|
* @summary Get current authenticated user
|
|
*/
|
|
export const getMe = async ( options?: RequestInit): Promise<AuthUser> => {
|
|
|
|
return customFetch<AuthUser>(getGetMeUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMeQueryKey = () => {
|
|
return [
|
|
`/api/auth/me`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetMeQueryOptions = <TData = Awaited<ReturnType<typeof getMe>>, TError = ErrorType<ErrorResponse>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMe>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetMeQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMe>>> = ({ signal }) => getMe({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMe>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetMeQueryResult = NonNullable<Awaited<ReturnType<typeof getMe>>>
|
|
export type GetMeQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get current authenticated user
|
|
*/
|
|
|
|
export function useGetMe<TData = Awaited<ReturnType<typeof getMe>>, TError = ErrorType<ErrorResponse>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMe>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetMeQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMePreferencesUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/me/preferences`
|
|
}
|
|
|
|
/**
|
|
* @summary Get current user's browse preferences
|
|
*/
|
|
export const getMePreferences = async ( options?: RequestInit): Promise<UserPreferences> => {
|
|
|
|
return customFetch<UserPreferences>(getGetMePreferencesUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMePreferencesQueryKey = () => {
|
|
return [
|
|
`/api/auth/me/preferences`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetMePreferencesQueryOptions = <TData = Awaited<ReturnType<typeof getMePreferences>>, TError = ErrorType<ErrorResponse>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMePreferences>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetMePreferencesQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMePreferences>>> = ({ signal }) => getMePreferences({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMePreferences>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetMePreferencesQueryResult = NonNullable<Awaited<ReturnType<typeof getMePreferences>>>
|
|
export type GetMePreferencesQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get current user's browse preferences
|
|
*/
|
|
|
|
export function useGetMePreferences<TData = Awaited<ReturnType<typeof getMePreferences>>, TError = ErrorType<ErrorResponse>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMePreferences>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetMePreferencesQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getUpdateMePreferencesUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/me/preferences`
|
|
}
|
|
|
|
/**
|
|
* @summary Update current user's browse preferences
|
|
*/
|
|
export const updateMePreferences = async (userPreferences: UserPreferences, options?: RequestInit): Promise<UserPreferences> => {
|
|
|
|
return customFetch<UserPreferences>(getUpdateMePreferencesUrl(),
|
|
{
|
|
...options,
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
userPreferences,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getUpdateMePreferencesMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateMePreferences>>, TError,{data: BodyType<UserPreferences>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof updateMePreferences>>, TError,{data: BodyType<UserPreferences>}, TContext> => {
|
|
|
|
const mutationKey = ['updateMePreferences'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateMePreferences>>, {data: BodyType<UserPreferences>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return updateMePreferences(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type UpdateMePreferencesMutationResult = NonNullable<Awaited<ReturnType<typeof updateMePreferences>>>
|
|
export type UpdateMePreferencesMutationBody = BodyType<UserPreferences>
|
|
export type UpdateMePreferencesMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Update current user's browse preferences
|
|
*/
|
|
export const useUpdateMePreferences = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateMePreferences>>, TError,{data: BodyType<UserPreferences>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof updateMePreferences>>,
|
|
TError,
|
|
{data: BodyType<UserPreferences>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getUpdateMePreferencesMutationOptions(options));
|
|
}
|
|
|
|
export const getGetMeWatchlistUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/auth/me/watchlist`
|
|
}
|
|
|
|
/**
|
|
* @summary Get current user's watchlist tools (premium)
|
|
*/
|
|
export const getMeWatchlist = async ( options?: RequestInit): Promise<ToolWithStats[]> => {
|
|
|
|
return customFetch<ToolWithStats[]>(getGetMeWatchlistUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getGetMeWatchlistQueryKey = () => {
|
|
return [
|
|
`/api/auth/me/watchlist`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getGetMeWatchlistQueryOptions = <TData = Awaited<ReturnType<typeof getMeWatchlist>>, TError = ErrorType<ErrorResponse>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMeWatchlist>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getGetMeWatchlistQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMeWatchlist>>> = ({ signal }) => getMeWatchlist({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMeWatchlist>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type GetMeWatchlistQueryResult = NonNullable<Awaited<ReturnType<typeof getMeWatchlist>>>
|
|
export type GetMeWatchlistQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary Get current user's watchlist tools (premium)
|
|
*/
|
|
|
|
export function useGetMeWatchlist<TData = Awaited<ReturnType<typeof getMeWatchlist>>, TError = ErrorType<ErrorResponse>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getMeWatchlist>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getGetMeWatchlistQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getListUsersUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/users`
|
|
}
|
|
|
|
/**
|
|
* @summary List all local users (admin only)
|
|
*/
|
|
export const listUsers = async ( options?: RequestInit): Promise<User[]> => {
|
|
|
|
return customFetch<User[]>(getListUsersUrl(),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListUsersQueryKey = () => {
|
|
return [
|
|
`/api/users`
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListUsersQueryOptions = <TData = Awaited<ReturnType<typeof listUsers>>, TError = ErrorType<ErrorResponse>>( options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listUsers>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListUsersQueryKey();
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listUsers>>> = ({ signal }) => listUsers({ signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listUsers>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListUsersQueryResult = NonNullable<Awaited<ReturnType<typeof listUsers>>>
|
|
export type ListUsersQueryError = ErrorType<ErrorResponse>
|
|
|
|
|
|
/**
|
|
* @summary List all local users (admin only)
|
|
*/
|
|
|
|
export function useListUsers<TData = Awaited<ReturnType<typeof listUsers>>, TError = ErrorType<ErrorResponse>>(
|
|
options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listUsers>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListUsersQueryOptions(options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getCreateUserUrl = () => {
|
|
|
|
|
|
|
|
|
|
return `/api/users`
|
|
}
|
|
|
|
/**
|
|
* @summary Create a new local user (admin only)
|
|
*/
|
|
export const createUser = async (userCreateInput: UserCreateInput, options?: RequestInit): Promise<User> => {
|
|
|
|
return customFetch<User>(getCreateUserUrl(),
|
|
{
|
|
...options,
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
userCreateInput,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getCreateUserMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: BodyType<UserCreateInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: BodyType<UserCreateInput>}, TContext> => {
|
|
|
|
const mutationKey = ['createUser'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createUser>>, {data: BodyType<UserCreateInput>}> = (props) => {
|
|
const {data} = props ?? {};
|
|
|
|
return createUser(data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type CreateUserMutationResult = NonNullable<Awaited<ReturnType<typeof createUser>>>
|
|
export type CreateUserMutationBody = BodyType<UserCreateInput>
|
|
export type CreateUserMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Create a new local user (admin only)
|
|
*/
|
|
export const useCreateUser = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createUser>>, TError,{data: BodyType<UserCreateInput>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof createUser>>,
|
|
TError,
|
|
{data: BodyType<UserCreateInput>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getCreateUserMutationOptions(options));
|
|
}
|
|
|
|
export const getUpdateUserUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/users/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Update user role (admin only)
|
|
*/
|
|
export const updateUser = async (id: number,
|
|
userRoleUpdate: UserRoleUpdate, options?: RequestInit): Promise<User> => {
|
|
|
|
return customFetch<User>(getUpdateUserUrl(id),
|
|
{
|
|
...options,
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
|
body: JSON.stringify(
|
|
userRoleUpdate,)
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getUpdateUserMutationOptions = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{id: number;data: BodyType<UserRoleUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{id: number;data: BodyType<UserRoleUpdate>}, TContext> => {
|
|
|
|
const mutationKey = ['updateUser'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof updateUser>>, {id: number;data: BodyType<UserRoleUpdate>}> = (props) => {
|
|
const {id,data} = props ?? {};
|
|
|
|
return updateUser(id,data,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type UpdateUserMutationResult = NonNullable<Awaited<ReturnType<typeof updateUser>>>
|
|
export type UpdateUserMutationBody = BodyType<UserRoleUpdate>
|
|
export type UpdateUserMutationError = ErrorType<ErrorResponse>
|
|
|
|
/**
|
|
* @summary Update user role (admin only)
|
|
*/
|
|
export const useUpdateUser = <TError = ErrorType<ErrorResponse>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof updateUser>>, TError,{id: number;data: BodyType<UserRoleUpdate>}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof updateUser>>,
|
|
TError,
|
|
{id: number;data: BodyType<UserRoleUpdate>},
|
|
TContext
|
|
> => {
|
|
return useMutation(getUpdateUserMutationOptions(options));
|
|
}
|
|
|
|
export const getDeleteUserUrl = (id: number,) => {
|
|
|
|
|
|
|
|
|
|
return `/api/users/${id}`
|
|
}
|
|
|
|
/**
|
|
* @summary Delete a user (admin only)
|
|
*/
|
|
export const deleteUser = async (id: number, options?: RequestInit): Promise<void> => {
|
|
|
|
return customFetch<void>(getDeleteUserUrl(id),
|
|
{
|
|
...options,
|
|
method: 'DELETE'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
export const getDeleteUserMutationOptions = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{id: number}, TContext> => {
|
|
|
|
const mutationKey = ['deleteUser'];
|
|
const {mutation: mutationOptions, request: requestOptions} = options ?
|
|
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
options
|
|
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
: {mutation: { mutationKey, }, request: undefined};
|
|
|
|
|
|
|
|
|
|
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteUser>>, {id: number}> = (props) => {
|
|
const {id} = props ?? {};
|
|
|
|
return deleteUser(id,requestOptions)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { mutationFn, ...mutationOptions }}
|
|
|
|
export type DeleteUserMutationResult = NonNullable<Awaited<ReturnType<typeof deleteUser>>>
|
|
|
|
export type DeleteUserMutationError = ErrorType<unknown>
|
|
|
|
/**
|
|
* @summary Delete a user (admin only)
|
|
*/
|
|
export const useDeleteUser = <TError = ErrorType<unknown>,
|
|
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteUser>>, TError,{id: number}, TContext>, request?: SecondParameter<typeof customFetch>}
|
|
): UseMutationResult<
|
|
Awaited<ReturnType<typeof deleteUser>>,
|
|
TError,
|
|
{id: number},
|
|
TContext
|
|
> => {
|
|
return useMutation(getDeleteUserMutationOptions(options));
|
|
}
|
|
|
|
export const getListAuditLogsUrl = (params?: ListAuditLogsParams,) => {
|
|
const normalizedParams = new URLSearchParams();
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
if (value !== undefined) {
|
|
normalizedParams.append(key, value === null ? 'null' : value.toString())
|
|
}
|
|
});
|
|
|
|
const stringifiedParams = normalizedParams.toString();
|
|
|
|
return stringifiedParams.length > 0 ? `/api/audit-logs?${stringifiedParams}` : `/api/audit-logs`
|
|
}
|
|
|
|
/**
|
|
* @summary List audit log entries (admin only)
|
|
*/
|
|
export const listAuditLogs = async (params?: ListAuditLogsParams, options?: RequestInit): Promise<AuditLog[]> => {
|
|
|
|
return customFetch<AuditLog[]>(getListAuditLogsUrl(params),
|
|
{
|
|
...options,
|
|
method: 'GET'
|
|
|
|
|
|
}
|
|
);}
|
|
|
|
|
|
|
|
|
|
|
|
export const getListAuditLogsQueryKey = (params?: ListAuditLogsParams,) => {
|
|
return [
|
|
`/api/audit-logs`, ...(params ? [params] : [])
|
|
] as const;
|
|
}
|
|
|
|
|
|
export const getListAuditLogsQueryOptions = <TData = Awaited<ReturnType<typeof listAuditLogs>>, TError = ErrorType<unknown>>(params?: ListAuditLogsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAuditLogs>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
) => {
|
|
|
|
const {query: queryOptions, request: requestOptions} = options ?? {};
|
|
|
|
const queryKey = queryOptions?.queryKey ?? getListAuditLogsQueryKey(params);
|
|
|
|
|
|
|
|
const queryFn: QueryFunction<Awaited<ReturnType<typeof listAuditLogs>>> = ({ signal }) => listAuditLogs(params, { signal, ...requestOptions });
|
|
|
|
|
|
|
|
|
|
|
|
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listAuditLogs>>, TError, TData> & { queryKey: QueryKey }
|
|
}
|
|
|
|
export type ListAuditLogsQueryResult = NonNullable<Awaited<ReturnType<typeof listAuditLogs>>>
|
|
export type ListAuditLogsQueryError = ErrorType<unknown>
|
|
|
|
|
|
/**
|
|
* @summary List audit log entries (admin only)
|
|
*/
|
|
|
|
export function useListAuditLogs<TData = Awaited<ReturnType<typeof listAuditLogs>>, TError = ErrorType<unknown>>(
|
|
params?: ListAuditLogsParams, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof listAuditLogs>>, TError, TData>, request?: SecondParameter<typeof customFetch>}
|
|
|
|
): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
|
|
|
|
const queryOptions = getListAuditLogsQueryOptions(params,options)
|
|
|
|
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & { queryKey: QueryKey };
|
|
|
|
return { ...query, queryKey: queryOptions.queryKey };
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|