import {z} from 'zod' export type GetApiApiV1PerformanceEmployeesEmployeeIdGoalsGoalIdAggregateArgs = {employeeId: string, goalId: string}; export type GetApiApiV1PerformanceEmployeesEmployeeIdGoalsGoalIdAggregateOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const transformedApiGoal = z.object({id: z.string().optional(), title: z.string().optional(), description: z.string().optional(), percentComplete: z.number().int().optional(), alignsWithOptionId: z.string().nullable().optional(), sharedWithEmployeeIds: z.array(z.number().int()).optional(), dueDate: z.string().optional(), completionDate: z.string().nullable().optional(), lastChangedDateTime: z.string().nullable().optional(), status: z.enum(["in_progress", "completed", "closed"]).optional(), milestones: z.array(z.object({id: z.number().int().optional(), employeeGoalId: z.number().int().optional(), title: z.string().optional(), currentValue: z.number().nullable().optional(), startValue: z.number().nullable().optional(), endValue: z.number().nullable().optional(), completedDateTime: z.string().optional(), lastUpdateDateTime: z.string().optional(), lastUpdateUserId: z.number().int().optional()})).nullable().optional(), actions: z.object({canEditGoalProgressBar: z.boolean().optional(), canEditGoalMilestoneProgressBar: z.boolean().optional()}).nullable().optional()}); export const getApiApiV1PerformanceEmployeesEmployeeIdGoalsGoalIdAggregateResponse = z.object({goal: transformedApiGoal.optional(), canAlign: z.boolean().optional(), canCreateGoals: z.boolean().optional(), alignsWithOptions: z.array(z.object({id: z.number().int().optional(), title: z.string().optional()})).optional(), comments: z.array(z.object({id: z.string().optional(), authorUserId: z.number().int().optional(), createdAt: z.string().optional(), text: z.string().optional(), canEdit: z.boolean().optional(), canDelete: z.boolean().optional()})).optional(), persons: z.array(z.object({employeeId: z.number().int().optional(), userId: z.number().int().optional(), displayFirstName: z.string().optional(), lastName: z.string().optional(), photoUrl: z.string().optional()})).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 }; /** * Get Goal Aggregate * * GET /api/v1/performance/employees/{employeeId}/goals/{goalId}/aggregate * * Also accepts auth: oauth */ export const getApiApiV1PerformanceEmployeesEmployeeIdGoalsGoalIdAggregate = async (args: GetApiApiV1PerformanceEmployeesEmployeeIdGoalsGoalIdAggregateArgs, options?: GetApiApiV1PerformanceEmployeesEmployeeIdGoalsGoalIdAggregateOptions) => { const {baseUrl = "https://companySubDomain.bamboohr.com", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/performance/employees/${encodeURIComponent(String(args.employeeId))}/goals/${encodeURIComponent(String(args.goalId))}/aggregate${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(getApiApiV1PerformanceEmployeesEmployeeIdGoalsGoalIdAggregateResponse, await res.json()) };