Download frontend/src/lib/api.ts from stadv/sipracd: direct link, hf CLI and curl.
- Browser
- Download file 5.66 kB
-
https://huggingface.co/spaces/stadv/sipracd/resolve/main/frontend/src/lib/api.ts
- Command line
-
hf download hf://spaces/stadv/sipracd/frontend/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/stadv/sipracd/resolve/main/frontend/src/lib/api.ts
5.66 kB
| import type { | |
| ActivityType, | |
| DashboardResponse, | |
| EvaluatorSummary, | |
| GoalPeriod, | |
| PaginatedResponse, | |
| RegistrationCard, | |
| RegistrationDetail, | |
| TeamMemberOption, | |
| TimelineItem, | |
| TimelineEntry, | |
| TimelineEntryCreatePayload, | |
| WorkItemCard, | |
| WorkItemCreatePayload, | |
| WorkItemDetail, | |
| WorkItemFormOptions, | |
| WorkItemReopenPayload, | |
| } from "./types"; | |
| const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? (import.meta.env.DEV ? "http://127.0.0.1:8000" : ""); | |
| async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> { | |
| const response = await fetch(`${API_BASE_URL}${path}`, { | |
| headers: { | |
| "Content-Type": "application/json", | |
| ...(init?.headers ?? {}), | |
| }, | |
| ...init, | |
| }); | |
| if (!response.ok) { | |
| const body = await response.text(); | |
| throw new Error(body || `Falha ao acessar ${path}`); | |
| } | |
| return response.json() as Promise<T>; | |
| } | |
| export const api = { | |
| getDashboard: () => apiFetch<DashboardResponse>("/dashboard"), | |
| getWorkItems: (params?: { status?: string; evaluatorId?: number; priority?: string; q?: string; month?: string }) => { | |
| const search = new URLSearchParams(); | |
| if (params?.status) search.set("status", params.status); | |
| if (params?.evaluatorId) search.set("evaluator_id", String(params.evaluatorId)); | |
| if (params?.priority) search.set("priority", params.priority); | |
| if (params?.q) search.set("q", params.q); | |
| if (params?.month) search.set("month", params.month); | |
| const query = search.toString(); | |
| return apiFetch<WorkItemCard[]>(`/work-items${query ? `?${query}` : ""}`); | |
| }, | |
| getWorkItemsPage: (params?: { status?: string; evaluatorId?: number; priority?: string; q?: string; month?: string; page?: number }) => { | |
| const search = new URLSearchParams(); | |
| if (params?.status) search.set("status", params.status); | |
| if (params?.evaluatorId) search.set("evaluator_id", String(params.evaluatorId)); | |
| if (params?.priority) search.set("priority", params.priority); | |
| if (params?.q) search.set("q", params.q); | |
| if (params?.month) search.set("month", params.month); | |
| if (params?.page) search.set("page", String(params.page)); | |
| const query = search.toString(); | |
| return apiFetch<PaginatedResponse<WorkItemCard>>(`/work-items/paged${query ? `?${query}` : ""}`); | |
| }, | |
| getRegistrations: (params?: { status?: string; evaluatorId?: number; priority?: string; q?: string; month?: string }) => { | |
| const search = new URLSearchParams(); | |
| if (params?.status) search.set("status", params.status); | |
| if (params?.evaluatorId) search.set("evaluator_id", String(params.evaluatorId)); | |
| if (params?.priority) search.set("priority", params.priority); | |
| if (params?.q) search.set("q", params.q); | |
| if (params?.month) search.set("month", params.month); | |
| const query = search.toString(); | |
| return apiFetch<RegistrationCard[]>(`/registrations${query ? `?${query}` : ""}`); | |
| }, | |
| getRegistrationsPage: (params?: { status?: string; evaluatorId?: number; priority?: string; q?: string; month?: string; page?: number }) => { | |
| const search = new URLSearchParams(); | |
| if (params?.status) search.set("status", params.status); | |
| if (params?.evaluatorId) search.set("evaluator_id", String(params.evaluatorId)); | |
| if (params?.priority) search.set("priority", params.priority); | |
| if (params?.q) search.set("q", params.q); | |
| if (params?.month) search.set("month", params.month); | |
| if (params?.page) search.set("page", String(params.page)); | |
| const query = search.toString(); | |
| return apiFetch<PaginatedResponse<RegistrationCard>>(`/registrations/paged${query ? `?${query}` : ""}`); | |
| }, | |
| getRegistration: (propertyId: number) => apiFetch<RegistrationDetail>(`/registrations/${propertyId}`), | |
| getWorkItem: (id: number) => apiFetch<WorkItemDetail>(`/work-items/${id}`), | |
| createWorkItem: (payload: WorkItemCreatePayload) => | |
| apiFetch<WorkItemDetail>("/work-items", { | |
| method: "POST", | |
| body: JSON.stringify(payload), | |
| }), | |
| updateWorkItem: (id: number, payload: WorkItemCreatePayload) => | |
| apiFetch<WorkItemDetail>(`/work-items/${id}`, { | |
| method: "PUT", | |
| body: JSON.stringify(payload), | |
| }), | |
| reopenWorkItem: (id: number, payload: WorkItemReopenPayload) => | |
| apiFetch<WorkItemDetail>(`/work-items/${id}/reopen`, { | |
| method: "POST", | |
| body: JSON.stringify(payload), | |
| }), | |
| createTimelineEntry: (id: number, payload: TimelineEntryCreatePayload) => | |
| apiFetch<TimelineEntry>(`/work-items/${id}/timeline`, { | |
| method: "POST", | |
| body: JSON.stringify(payload), | |
| }), | |
| updateTimelineEntry: (workItemId: number, entryId: number, payload: TimelineEntryCreatePayload) => | |
| apiFetch<TimelineEntry>(`/work-items/${workItemId}/timeline/${entryId}`, { | |
| method: "PUT", | |
| body: JSON.stringify(payload), | |
| }), | |
| deleteTimelineEntry: (workItemId: number, entryId: number) => | |
| apiFetch<{ status: string }>(`/work-items/${workItemId}/timeline/${entryId}`, { | |
| method: "DELETE", | |
| }), | |
| getEvaluators: (params?: { month?: string }) => { | |
| const search = new URLSearchParams(); | |
| if (params?.month) search.set("month", params.month); | |
| const query = search.toString(); | |
| return apiFetch<EvaluatorSummary[]>(`/evaluators${query ? `?${query}` : ""}`); | |
| }, | |
| getPriorityOptions: () => apiFetch<string[]>("/priority-options"), | |
| getTeamMembers: () => apiFetch<TeamMemberOption[]>("/team-members"), | |
| getTimeline: () => apiFetch<TimelineItem[]>("/timeline"), | |
| getGoals: () => apiFetch<GoalPeriod[]>("/goal-periods"), | |
| getActivityTypes: () => apiFetch<ActivityType[]>("/activity-types"), | |
| getWorkItemFormOptions: () => apiFetch<WorkItemFormOptions>("/work-item-form-options"), | |
| }; | |