diff --git a/frontend/src/api/choreLogs.ts b/frontend/src/api/choreLogs.ts new file mode 100644 index 0000000..217a6e2 --- /dev/null +++ b/frontend/src/api/choreLogs.ts @@ -0,0 +1,125 @@ +/** + * API service for chore completion logs and reporting + */ +import api from './axios'; + +// Interfaces +export interface ChoreCompletionLog { + id: number; + chore_id: number; + user_id: number; + completed_at: string; + notes?: string; + verified_by_user_id?: number; + created_at: string; + chore_title?: string; + user_name?: string; + user_avatar?: string; + verified_by_name?: string; +} + +export interface WeeklyChoreReport { + start_date: string; + end_date: string; + total_completions: number; + completions_by_user: Record; + completions_by_chore: Record; + completions_by_day: Record; + top_performers: Array<{ + username: string; + count: number; + avatar_url?: string; + }>; + recent_completions: ChoreCompletionLog[]; +} + +export interface UserChoreStats { + user_id: number; + username: string; + full_name?: string; + avatar_url?: string; + total_completions: number; + completions_this_week: number; + completions_this_month: number; + favorite_chore?: string; + recent_completions: ChoreCompletionLog[]; +} + +export interface CompleteChoreRequest { + notes?: string; +} + +export interface CompletionLogsParams { + skip?: number; + limit?: number; + chore_id?: number; + user_id?: number; + start_date?: string; + end_date?: string; +} + +// Service +export const choreLogsService = { + /** + * Complete a chore and log it + */ + async completeChore(choreId: number, notes?: string): Promise { + const response = await api.post( + `/api/v1/chores/${choreId}/complete`, + { notes } + ); + return response.data; + }, + + /** + * Get completion logs with optional filters + */ + async getCompletionLogs(params?: CompletionLogsParams): Promise { + const response = await api.get('/api/v1/chores/completions', { + params, + }); + return response.data; + }, + + /** + * Get weekly report + */ + async getWeeklyReport(userId?: number, weeksAgo: number = 0): Promise { + const response = await api.get('/api/v1/chores/reports/weekly', { + params: { + user_id: userId, + weeks_ago: weeksAgo, + }, + }); + return response.data; + }, + + /** + * Get user statistics + */ + async getUserStats(userId: number): Promise { + const response = await api.get( + `/api/v1/chores/reports/user/${userId}` + ); + return response.data; + }, + + /** + * Verify a completion + */ + async verifyCompletion(logId: number): Promise { + const response = await api.post( + `/api/v1/chores/completions/${logId}/verify` + ); + return response.data; + }, + + /** + * Delete a completion log + */ + async deleteCompletionLog(logId: number): Promise { + await api.delete(`/api/v1/chores/completions/${logId}`); + }, +}; + +export default choreLogsService;