import {z} from 'zod' export type GetApiV1OrgOrgIdAssessmentAssessmentIdPeerReviewerCountsArgs = {orgId: string, assessmentId: string, personIds?: string | undefined, formResponseId?: string | undefined}; export type GetApiV1OrgOrgIdAssessmentAssessmentIdPeerReviewerCountsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const peerReviewerCount = z.object({personId: z.string(), count: z.number().int(), status: z.enum(["UNDER", "NEAR", "AT", "OVER"])}); export const peerReviewerCounts = z.object({max: z.number().int().optional(), counts: z.array(peerReviewerCount).optional(), fullPersonIds: z.array(z.string()), minPicks: z.number().int().optional(), canOverride: z.boolean().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Return how many times each person has been picked as a peer reviewer in a review cycle with a peer reviewer cap. Callers without full read access to the review cycle must pass personIds and only get which of those people are full. With formResponseId, anyone who can approve that request gets the counts for its peers, the fewest peers it may have, and whether they can approve past the cap. * * GET /v1/org/{orgId}/assessment/{assessmentId}/peer-reviewer-counts */ export const getApiV1OrgOrgIdAssessmentAssessmentIdPeerReviewerCounts = async (args: GetApiV1OrgOrgIdAssessmentAssessmentIdPeerReviewerCountsArgs, options?: GetApiV1OrgOrgIdAssessmentAssessmentIdPeerReviewerCountsOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.personIds != null) query.append("personIds", String(args.personIds)) if (args.formResponseId != null) query.append("formResponseId", String(args.formResponseId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/org/${encodeURIComponent(String(args.orgId))}/assessment/${encodeURIComponent(String(args.assessmentId))}/peer-reviewer-counts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(peerReviewerCounts, await res.json()) };