import {z} from 'zod' export type GetApiApiV1PerformanceEmployeesEmployeeIdGoalsAggregateArgs = {employeeId: string, filter?: string | undefined}; export type GetApiApiV1PerformanceEmployeesEmployeeIdGoalsAggregateOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const goalFiltersV1 = z.object({filters: z.array(z.object({id: z.enum(["status-inProgress", "status-completed"]).optional(), name: z.enum(["In Progress", "Completed"]).optional(), count: z.number().int().optional()})).optional()}); 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 getApiApiV1PerformanceEmployeesEmployeeIdGoalsAggregateResponse = z.object({canAlign: z.boolean().optional(), canCreateGoals: z.boolean().optional(), filters: goalFiltersV1.optional(), selectedFilter: z.string().optional(), goals: z.array(transformedApiGoal).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(), comments: z.array(z.object({goalId: z.number().int().optional(), commentCount: z.number().int().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 Goals Aggregate (v1) * * GET /api/v1/performance/employees/{employeeId}/goals/aggregate * * Also accepts auth: oauth */ export const getApiApiV1PerformanceEmployeesEmployeeIdGoalsAggregate = async (args: GetApiApiV1PerformanceEmployeesEmployeeIdGoalsAggregateArgs, options?: GetApiApiV1PerformanceEmployeesEmployeeIdGoalsAggregateOptions) => { 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 (args.filter != null) query.append("filter", String(args.filter)) 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/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(getApiApiV1PerformanceEmployeesEmployeeIdGoalsAggregateResponse, await res.json()) };