Update chores API: Add multi-user support, birthday filtering, and points
- Added AssignedUser interface with birthday and completed_at fields
- Updated Chore interface with assigned_users array and points field
- Added assigned_user_ids to CreateChoreRequest and UpdateChoreRequest
- Added query params to getChores: user_id and exclude_birthdays
- Added assignUsers method for POST /chores/{id}/assign endpoint
- Updated frequency enum to include 'on_trigger' and 'fortnightly'
This commit is contained in:
@@ -1,14 +1,24 @@
|
||||
import api from './axios';
|
||||
|
||||
export interface AssignedUser {
|
||||
id: number;
|
||||
username: string;
|
||||
full_name: string;
|
||||
birthday?: string;
|
||||
completed_at?: string;
|
||||
}
|
||||
|
||||
export interface Chore {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string;
|
||||
description?: string;
|
||||
room: string;
|
||||
frequency: 'daily' | 'weekly' | 'monthly' | 'once';
|
||||
frequency: 'daily' | 'weekly' | 'fortnightly' | 'monthly' | 'on_trigger';
|
||||
points: number;
|
||||
status: 'pending' | 'in_progress' | 'completed' | 'skipped';
|
||||
assigned_to?: number;
|
||||
assigned_user?: {
|
||||
assigned_users: AssignedUser[]; // Multiple users
|
||||
assigned_user_id?: number; // Legacy field
|
||||
assigned_user?: { // Legacy field
|
||||
id: number;
|
||||
username: string;
|
||||
full_name: string;
|
||||
@@ -23,8 +33,9 @@ export interface CreateChoreRequest {
|
||||
title: string;
|
||||
description?: string;
|
||||
room: string;
|
||||
frequency: 'daily' | 'weekly' | 'monthly' | 'once';
|
||||
assigned_to?: number;
|
||||
frequency: 'daily' | 'weekly' | 'fortnightly' | 'monthly' | 'on_trigger';
|
||||
points?: number;
|
||||
assigned_user_ids?: number[]; // Multiple users
|
||||
due_date?: string;
|
||||
}
|
||||
|
||||
@@ -32,15 +43,16 @@ export interface UpdateChoreRequest {
|
||||
title?: string;
|
||||
description?: string;
|
||||
room?: string;
|
||||
frequency?: 'daily' | 'weekly' | 'monthly' | 'once';
|
||||
frequency?: 'daily' | 'weekly' | 'fortnightly' | 'monthly' | 'on_trigger';
|
||||
points?: number;
|
||||
status?: 'pending' | 'in_progress' | 'completed' | 'skipped';
|
||||
assigned_to?: number;
|
||||
assigned_user_ids?: number[]; // Multiple users
|
||||
due_date?: string;
|
||||
}
|
||||
|
||||
export const choreService = {
|
||||
async getChores(): Promise<Chore[]> {
|
||||
const response = await api.get<Chore[]>('/api/v1/chores');
|
||||
async getChores(params?: { user_id?: number; exclude_birthdays?: boolean }): Promise<Chore[]> {
|
||||
const response = await api.get<Chore[]>('/api/v1/chores', { params });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
@@ -69,4 +81,9 @@ export const choreService = {
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async assignUsers(choreId: number, userIds: number[]): Promise<Chore> {
|
||||
const response = await api.post<Chore>(`/api/v1/chores/${choreId}/assign`, userIds);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user