31 lines
934 B
TypeScript
31 lines
934 B
TypeScript
import { cache } from "react";
|
|
import { fetchGanttApi } from "@/lib/data/gantt-api";
|
|
import type { Task } from "@/lib/data/tasks";
|
|
import type { Project, Sprint } from "@/lib/data/projects";
|
|
|
|
interface SnapshotResponse {
|
|
tasks?: Task[];
|
|
projects?: Project[];
|
|
sprints?: Sprint[];
|
|
}
|
|
|
|
export interface GanttSnapshot {
|
|
tasks: Task[];
|
|
projects: Project[];
|
|
sprints: Sprint[];
|
|
}
|
|
|
|
export const fetchGanttSnapshot = cache(async (): Promise<GanttSnapshot> => {
|
|
try {
|
|
const response = await fetchGanttApi<SnapshotResponse>("/tasks?scope=all");
|
|
return {
|
|
tasks: Array.isArray(response.tasks) ? response.tasks : [],
|
|
projects: Array.isArray(response.projects) ? response.projects : [],
|
|
sprints: Array.isArray(response.sprints) ? response.sprints : [],
|
|
};
|
|
} catch (error) {
|
|
console.error("Error fetching gantt snapshot from API:", error);
|
|
return { tasks: [], projects: [], sprints: [] };
|
|
}
|
|
});
|