Add chore service API

This commit is contained in:
2026-01-27 22:21:28 +11:00
parent 6bcc0554e0
commit d2f6fbd886

View File

@@ -0,0 +1,72 @@
import api from './axios';
export interface Chore {
id: number;
title: string;
description: string;
room: string;
frequency: 'daily' | 'weekly' | 'monthly' | 'once';
status: 'pending' | 'in_progress' | 'completed' | 'skipped';
assigned_to?: number;
assigned_user?: {
id: number;
username: string;
full_name: string;
};
due_date?: string;
completed_at?: string;
created_at: string;
updated_at: string;
}
export interface CreateChoreRequest {
title: string;
description?: string;
room: string;
frequency: 'daily' | 'weekly' | 'monthly' | 'once';
assigned_to?: number;
due_date?: string;
}
export interface UpdateChoreRequest {
title?: string;
description?: string;
room?: string;
frequency?: 'daily' | 'weekly' | 'monthly' | 'once';
status?: 'pending' | 'in_progress' | 'completed' | 'skipped';
assigned_to?: number;
due_date?: string;
}
export const choreService = {
async getChores(): Promise<Chore[]> {
const response = await api.get<Chore[]>('/api/v1/chores');
return response.data;
},
async getChore(id: number): Promise<Chore> {
const response = await api.get<Chore>(`/api/v1/chores/${id}`);
return response.data;
},
async createChore(chore: CreateChoreRequest): Promise<Chore> {
const response = await api.post<Chore>('/api/v1/chores', chore);
return response.data;
},
async updateChore(id: number, chore: UpdateChoreRequest): Promise<Chore> {
const response = await api.put<Chore>(`/api/v1/chores/${id}`, chore);
return response.data;
},
async deleteChore(id: number): Promise<void> {
await api.delete(`/api/v1/chores/${id}`);
},
async completeChore(id: number): Promise<Chore> {
const response = await api.put<Chore>(`/api/v1/chores/${id}`, {
status: 'completed',
});
return response.data;
},
};