feat: Implement backend API and basic frontend structure
Adds initial backend API endpoints for fetching users and attendances, including basic filtering. Sets up the frontend routing with a layout component and includes placeholder pages for dashboard, users, and login. Refactors the README for local development setup.
This commit is contained in:
68
services/dataService.ts
Normal file
68
services/dataService.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
import { Attendance, DashboardFilter, User } from '../types';
|
||||
|
||||
// URL do Backend que criamos (backend/index.js)
|
||||
// Certifique-se de rodar o backend com 'node backend/index.js'
|
||||
const API_URL = 'http://localhost:3001/api';
|
||||
|
||||
export const getAttendances = async (tenantId: string, filter: DashboardFilter): Promise<Attendance[]> => {
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
params.append('tenantId', tenantId);
|
||||
|
||||
if (filter.dateRange.start) params.append('startDate', filter.dateRange.start.toISOString());
|
||||
if (filter.dateRange.end) params.append('endDate', filter.dateRange.end.toISOString());
|
||||
|
||||
if (filter.userId && filter.userId !== 'all') params.append('userId', filter.userId);
|
||||
if (filter.teamId && filter.teamId !== 'all') params.append('teamId', filter.teamId);
|
||||
|
||||
const response = await fetch(`${API_URL}/attendances?${params.toString()}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Falha ao buscar atendimentos do servidor');
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("API Error (getAttendances):", error);
|
||||
// Fallback vazio ou lançar erro para a UI tratar
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const getUsers = async (tenantId: string): Promise<User[]> => {
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
if (tenantId !== 'all') params.append('tenantId', tenantId);
|
||||
|
||||
const response = await fetch(`${API_URL}/users?${params.toString()}`);
|
||||
if (!response.ok) throw new Error('Falha ao buscar usuários');
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("API Error (getUsers):", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const getUserById = async (id: string): Promise<User | undefined> => {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/users/${id}`);
|
||||
if (!response.ok) return undefined;
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("API Error (getUserById):", error);
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const getAttendanceById = async (id: string): Promise<Attendance | undefined> => {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/attendances/${id}`);
|
||||
if (!response.ok) return undefined;
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("API Error (getAttendanceById):", error);
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user