Phase 3.1: Add choreLogs API service for frontend
This commit is contained in:
125
frontend/src/api/choreLogs.ts
Normal file
125
frontend/src/api/choreLogs.ts
Normal file
@@ -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<string, number>;
|
||||
completions_by_chore: Record<string, number>;
|
||||
completions_by_day: Record<string, number>;
|
||||
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<ChoreCompletionLog> {
|
||||
const response = await api.post<ChoreCompletionLog>(
|
||||
`/api/v1/chores/${choreId}/complete`,
|
||||
{ notes }
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get completion logs with optional filters
|
||||
*/
|
||||
async getCompletionLogs(params?: CompletionLogsParams): Promise<ChoreCompletionLog[]> {
|
||||
const response = await api.get<ChoreCompletionLog[]>('/api/v1/chores/completions', {
|
||||
params,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get weekly report
|
||||
*/
|
||||
async getWeeklyReport(userId?: number, weeksAgo: number = 0): Promise<WeeklyChoreReport> {
|
||||
const response = await api.get<WeeklyChoreReport>('/api/v1/chores/reports/weekly', {
|
||||
params: {
|
||||
user_id: userId,
|
||||
weeks_ago: weeksAgo,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get user statistics
|
||||
*/
|
||||
async getUserStats(userId: number): Promise<UserChoreStats> {
|
||||
const response = await api.get<UserChoreStats>(
|
||||
`/api/v1/chores/reports/user/${userId}`
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Verify a completion
|
||||
*/
|
||||
async verifyCompletion(logId: number): Promise<ChoreCompletionLog> {
|
||||
const response = await api.post<ChoreCompletionLog>(
|
||||
`/api/v1/chores/completions/${logId}/verify`
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a completion log
|
||||
*/
|
||||
async deleteCompletionLog(logId: number): Promise<void> {
|
||||
await api.delete(`/api/v1/chores/completions/${logId}`);
|
||||
},
|
||||
};
|
||||
|
||||
export default choreLogsService;
|
||||
Reference in New Issue
Block a user