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

256 lines
11 KiB
TypeScript

/**
* Generated by orval 🍺
* Do not edit manually.
* Lincodex API
* OpenAPI spec version: 0.1.0
*/
import {
useMutation,
useQuery
} from '@tanstack/react-query';
import type {
DataTag,
DefinedInitialDataOptions,
DefinedUseQueryResult,
MutationFunction,
QueryClient,
QueryFunction,
QueryKey,
UndefinedInitialDataOptions,
UseMutationOptions,
UseMutationResult,
UseQueryOptions,
UseQueryResult
} from '@tanstack/react-query';
import type {
CandidateQuestionnaire,
CandidateQuestionnaireUpdate,
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 getGetMyQuestionnaireUrl = () => {
return `/api/v1/me/questionnaire`
}
/**
* Requires the session cookie of a candidate account. The candidate comes from the session, never from a request parameter. A candidate who has not saved the questionnaire yet gets 200 with version 0 and no specializations rather than 404, so the client reads the version for the first save in the same way as for later ones and a missing questionnaire is not an error state.
*
* The response never contains a confirmed grade or a category; those come only from assessment results. A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account answers 403 forbidden.
* @summary Read the questionnaire of the current candidate.
*/
export const getMyQuestionnaire = async ( options?: Parameters<typeof apiRequest>[1]): Promise<CandidateQuestionnaire> => {
return apiRequest<CandidateQuestionnaire>(getGetMyQuestionnaireUrl(),
{
...options,
method: 'GET'
}
);}
export const getGetMyQuestionnaireQueryKey = () => {
return [
`/api/v1/me/questionnaire`
] as const;
}
export const getGetMyQuestionnaireQueryOptions = <TData = Awaited<ReturnType<typeof getMyQuestionnaire>>, TError = ErrorType<Problem>>( options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyQuestionnaire>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetMyQuestionnaireQueryKey();
const queryFn: QueryFunction<Awaited<ReturnType<typeof getMyQuestionnaire>>> = ({ signal }) => getMyQuestionnaire({ signal, ...requestOptions });
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getMyQuestionnaire>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetMyQuestionnaireQueryResult = NonNullable<Awaited<ReturnType<typeof getMyQuestionnaire>>>
export type GetMyQuestionnaireQueryError = ErrorType<Problem>
export function useGetMyQuestionnaire<TData = Awaited<ReturnType<typeof getMyQuestionnaire>>, TError = ErrorType<Problem>>(
options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyQuestionnaire>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getMyQuestionnaire>>,
TError,
Awaited<ReturnType<typeof getMyQuestionnaire>>
> , 'initialData'
>, request?: SecondParameter<typeof apiRequest>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetMyQuestionnaire<TData = Awaited<ReturnType<typeof getMyQuestionnaire>>, TError = ErrorType<Problem>>(
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyQuestionnaire>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getMyQuestionnaire>>,
TError,
Awaited<ReturnType<typeof getMyQuestionnaire>>
> , 'initialData'
>, request?: SecondParameter<typeof apiRequest>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetMyQuestionnaire<TData = Awaited<ReturnType<typeof getMyQuestionnaire>>, TError = ErrorType<Problem>>(
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyQuestionnaire>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Read the questionnaire of the current candidate.
*/
export function useGetMyQuestionnaire<TData = Awaited<ReturnType<typeof getMyQuestionnaire>>, TError = ErrorType<Problem>>(
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getMyQuestionnaire>>, TError, TData>>, request?: SecondParameter<typeof apiRequest>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetMyQuestionnaireQueryOptions(options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
return withQueryKey(query, queryOptions.queryKey);
}
export const getSaveMyQuestionnaireUrl = () => {
return `/api/v1/me/questionnaire`
}
/**
* Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token, and an allowed Origin. The body is the complete new state: one or two specializations, each with a self-assessed grade, task languages, stack tags, and stated experience or null, and the working context. It replaces the stored questionnaire as a whole.
*
* Self-assessment is a claim. It influences where the assessment starts and which grade the assessment step offers first, but it adds no points and never writes a confirmed grade or a category: a self-assessed `senior`, or the word "Senior" in a stack tag, never assigns the Senior category. A real profile stays invisible to employers until an assessment confirms a category. Choosing a specialization whose test is `in_development` is allowed; no assessment starts for it until its bank is published. Removing a specialization from the questionnaire does not change assessment results.
*
* Optimistic concurrency uses `expected_version` in the body: the client sends the `version` it read, 0 for the first save. If it is not the current version, the server answers 412 version_conflict and changes nothing; the client reads the questionnaire again. The version travels in the body rather than in If-Match because the generated client cannot read the ETag response header yet. The status and code are the same as for a failed If-Match, since the client action is the same.
*
* The operation needs no Idempotency-Key: it replaces the whole state and is idempotent. A body whose specializations and working context equal the stored ones changes nothing, keeps the version, and answers 200 with the current questionnaire even when `expected_version` is older, so a retry after a lost response of a successful save succeeds instead of failing with 412.
*
* Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400), account scenario (403 forbidden for an employer), domain rules (400), then the version (412). The schema rejects more than two specializations, an unknown grade, specialization, or task language, and unknown fields. The server also rejects a repeated specialization and a task language that the specialization's published bank does not offer, with 400 validation_failed and pointers to the items, for example `/specializations/1/specialization` or `/specializations/0/task_languages/0`.
*
* A successful save on the onboarding step candidate_questionnaire advances the account to candidate_assessment (planned).
* @summary Replace the questionnaire of the current candidate.
*/
export const saveMyQuestionnaire = async (candidateQuestionnaireUpdate: CandidateQuestionnaireUpdate, options?: Parameters<typeof apiRequest>[1]): Promise<CandidateQuestionnaire> => {
const getHeaders = (h?: NonNullable<RequestInit['headers']>): Record<string, string | readonly string[]> => {
if (!h) return {};
if (h instanceof Headers) return Object.fromEntries(h.entries());
if (Symbol.iterator in h) {
return Object.fromEntries(
Array.from(h as Iterable<Iterable<string>>, (entry) => Array.from(entry) as [string, string]),
);
}
const headers: Record<string, string | readonly string[]> = {};
for (const [name, value] of Object.entries<string | readonly string[] | undefined>(h)) {
if (value !== undefined) headers[name] = value;
}
return headers;
};
return apiRequest<CandidateQuestionnaire>(getSaveMyQuestionnaireUrl(),
{
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...getHeaders(options?.headers) },
body: JSON.stringify(candidateQuestionnaireUpdate)
}
);}
export const getSaveMyQuestionnaireMutationKey = () => ['saveMyQuestionnaire'] as const;
export const getSaveMyQuestionnaireMutationOptions = <TError = ErrorType<Problem>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof saveMyQuestionnaire>>, TError,SaveMyQuestionnaireMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
): UseMutationOptions<Awaited<ReturnType<typeof saveMyQuestionnaire>>, TError,SaveMyQuestionnaireMutationVariables, TContext> => {
const mutationKey = getSaveMyQuestionnaireMutationKey();
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 saveMyQuestionnaire>>, SaveMyQuestionnaireMutationVariables> = (props) => {
const {data} = props ?? {};
return saveMyQuestionnaire(data,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type SaveMyQuestionnaireMutationResult = NonNullable<Awaited<ReturnType<typeof saveMyQuestionnaire>>>
export type SaveMyQuestionnaireMutationBody = CandidateQuestionnaireUpdate
export type SaveMyQuestionnaireMutationError = ErrorType<Problem>
export type SaveMyQuestionnaireMutationVariables = {data: CandidateQuestionnaireUpdate}
/**
* @summary Replace the questionnaire of the current candidate.
*/
export const useSaveMyQuestionnaire = <TError = ErrorType<Problem>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof saveMyQuestionnaire>>, TError,SaveMyQuestionnaireMutationVariables, TContext>, request?: SecondParameter<typeof apiRequest>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof saveMyQuestionnaire>>,
TError,
SaveMyQuestionnaireMutationVariables,
TContext
> => {
return useMutation(getSaveMyQuestionnaireMutationOptions(options), queryClient);
}