tududi/frontend/utils/projectsService.ts
Chris 03f38f05dc
Setup intelligence (#84)
* Add next suggestions and remove console logs

* Add pomodoro timer

* Add pomodoro switch in settings

* Fix pomodoro setting

* Add timezones to settings

* Fix an issue with password reset

* Cleanup

* Sort tags alphabetically

* Clean up today's view

* Add an indicator for repeatedly added to today

* Refactor tags

* Add due date today item

* Move recurrence to the subtitle area

* Fix today layout

* Add a badge to Inbox items

* Move inbox badge to sidebar

* Add quotes and progress bar

* Add translations for quotes

* Fix test issues

* Add helper script for docker local

* Set up overdue tasks

* Add  linux/arm/v7 build to deploy script

* Add  linux/arm/v7 build to deploy script pt2

* Fix an issue with helmet and SSL

* Add volume db persistence

* Fix cog icon issues
2025-06-27 14:02:18 +03:00

94 lines
2.9 KiB
TypeScript

import { Project } from "../entities/Project";
import { handleAuthResponse } from "./authUtils";
export const fetchProjects = async (activeFilter = "all", areaFilter = ""): Promise<Project[]> => {
let url = `/api/projects`;
const params = new URLSearchParams();
if (activeFilter !== "all") params.append("active", activeFilter);
if (areaFilter) params.append("area_id", areaFilter);
if (params.toString()) url += `?${params.toString()}`;
const response = await fetch(url, {
credentials: 'include',
headers: { Accept: 'application/json' },
});
await handleAuthResponse(response, 'Failed to fetch projects.');
const data = await response.json();
return data.projects || data;
};
export const fetchGroupedProjects = async (activeFilter = "all", areaFilter = ""): Promise<Record<string, Project[]>> => {
let url = `/api/projects`;
const params = new URLSearchParams();
params.append("grouped", "true");
if (activeFilter !== "all") params.append("active", activeFilter);
if (areaFilter) params.append("area_id", areaFilter);
if (params.toString()) url += `?${params.toString()}`;
const response = await fetch(url, {
credentials: 'include',
headers: { Accept: 'application/json' },
});
await handleAuthResponse(response, 'Failed to fetch projects.');
const data = await response.json();
return data;
};
export const fetchProjectById = async (projectId: string): Promise<Project> => {
const response = await fetch(`/api/project/${projectId}`, {
credentials: 'include',
headers: { Accept: 'application/json' },
});
await handleAuthResponse(response, 'Failed to fetch project details.');
return await response.json();
};
export const createProject = async (projectData: Partial<Project>): Promise<Project> => {
const response = await fetch('/api/project', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify(projectData),
});
await handleAuthResponse(response, 'Failed to create project.');
return await response.json();
};
export const updateProject = async (projectId: number, projectData: Partial<Project>): Promise<Project> => {
const response = await fetch(`/api/project/${projectId}`, {
method: 'PATCH',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify(projectData),
});
await handleAuthResponse(response, 'Failed to update project.');
return await response.json();
};
export const deleteProject = async (projectId: number): Promise<void> => {
const response = await fetch(`/api/project/${projectId}`, {
method: 'DELETE',
credentials: 'include',
headers: {
'Accept': 'application/json',
},
});
await handleAuthResponse(response, 'Failed to delete project.');
};