Files
lincodex/frontend/src/shared/api/endpoints/consent/consent.ts
T

167 lines
7.2 KiB
TypeScript

/**
* Generated by orval 🍺
* Do not edit manually.
* Lincodex API
* OpenAPI spec version: 0.1.0
*/
import {
useQuery
} from '@tanstack/react-query';
import type {
DataTag,
DefinedInitialDataOptions,
DefinedUseQueryResult,
QueryClient,
QueryFunction,
QueryKey,
UndefinedInitialDataOptions,
UseQueryOptions,
UseQueryResult
} from '@tanstack/react-query';
import type {
ConsentRecordList,
ListMyConsentsParams,
Problem
} from '../../schemas';
import { apiRequest } from '../../client';
import type { ErrorType } from '../../client';
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
const withQueryKey = <T extends object, K>(query: T, queryKey: K): T & { queryKey: K } => {
const result = { queryKey } as T & { queryKey: K };
for (const key of Object.keys(query)) {
// The explicit queryKey always wins, matching the previous
// `{ ...query, queryKey }` spread where it was set last.
if (key === 'queryKey') continue;
Object.defineProperty(result, key, {
enumerable: true,
configurable: true,
get: () => (query as Record<string, unknown>)[key],
});
}
return result;
};
export const getListMyConsentsUrl = (params?: ListMyConsentsParams,) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : String(value))
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0 ? `/api/v1/me/consents?${stringifiedParams}` : `/api/v1/me/consents`
}
/**
* Requires the session cookie of a candidate or an employer account. The subject comes from the session, never from a request parameter, so the response holds only the caller's own consents: no request can name another account, and records of other accounts are never listed. Returns a page of the consent ledger of the account, newest grant first with the identifier as the tie-breaker, with cursor pagination.
*
* The ledger is append-only. Every grant is a record with its purpose, the accepted text version, the source, and the grant time; the server also stores the hash of exactly the text the subject saw. A newer text version of the same purpose is a new record, and the earlier one becomes `superseded` without any change. A revocation stamps every unrevoked record of the purpose, and for c4 of one organization, once; a later grant is a new record. Purposes are independent.
*
* Without `state` the page lists the whole history; `state=active` lists the consents that hold now, one per purpose for c1, c2, c3, and c5 and one per accepted invitation for c4. A c4 record names the organization with the name its consent text showed (a snapshot that a later rename does not change), the selected contact fields, and the invitation with its terms version; it never carries a contact value. A c2 record proves the consent to the publication text; the published field set and its changes are evidence of the publication history.
*
* Granting c1, c2, c3, and c5 in the consent settings and revoking any purpose are planned operations of this tag; c1 is given at registration and c4 only in AcceptMyInvitation.
*
* Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated. A malformed `limit`, `cursor`, or `state` answers 400 validation_failed.
* @summary List the consents of the current account with their history.
*/
export const listMyConsents = async (params?: ListMyConsentsParams, options?: Parameters<typeof apiRequest>[1]): Promise<ConsentRecordList> => {
return apiRequest<ConsentRecordList>(getListMyConsentsUrl(params),
{
...options,
method: 'GET'
}
);}
export const getListMyConsentsQueryKey = (params?: ListMyConsentsParams,) => {
return [
`/api/v1/me/consents`, ...(params ? [params] : [])
] as const;
}
export const getListMyConsentsQueryOptions = <TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(params?: ListMyConsentsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getListMyConsentsQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof listMyConsents>>> = ({ signal }) => listMyConsents(params, { signal, ...requestOptions });
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type ListMyConsentsQueryResult = NonNullable<Awaited<ReturnType<typeof listMyConsents>>>
export type ListMyConsentsQueryError = ErrorType<Problem>
export function useListMyConsents<TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(
params: undefined | ListMyConsentsParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof listMyConsents>>,
TError,
Awaited<ReturnType<typeof listMyConsents>>
> , 'initialData'
>, request?: SecondParameter<typeof apiRequest>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useListMyConsents<TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(
params?: ListMyConsentsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof listMyConsents>>,
TError,
Awaited<ReturnType<typeof listMyConsents>>
> , 'initialData'
>, request?: SecondParameter<typeof apiRequest>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useListMyConsents<TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(
params?: ListMyConsentsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary List the consents of the current account with their history.
*/
export function useListMyConsents<TData = Awaited<ReturnType<typeof listMyConsents>>, TError = ErrorType<Problem>>(
params?: ListMyConsentsParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof listMyConsents>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getListMyConsentsQueryOptions(params,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
return withQueryKey(query, queryOptions.queryKey);
}