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';
|
import api from './axios';
|
||||||
|
|
||||||
|
export interface AssignedUser {
|
||||||
|
id: number;
|
||||||
|
username: string;
|
||||||
|
full_name: string;
|
||||||
|
birthday?: string;
|
||||||
|
completed_at?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Chore {
|
export interface Chore {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description?: string;
|
||||||
room: string;
|
room: string;
|
||||||
frequency: 'daily' | 'weekly' | 'monthly' | 'once';
|
frequency: 'daily' | 'weekly' | 'fortnightly' | 'monthly' | 'on_trigger';
|
||||||
|
points: number;
|
||||||
status: 'pending' | 'in_progress' | 'completed' | 'skipped';
|
status: 'pending' | 'in_progress' | 'completed' | 'skipped';
|
||||||
assigned_to?: number;
|
assigned_users: AssignedUser[]; // Multiple users
|
||||||
assigned_user?: {
|
assigned_user_id?: number; // Legacy field
|
||||||
|
assigned_user?: { // Legacy field
|
||||||
id: number;
|
id: number;
|
||||||
username: string;
|
username: string;
|
||||||
full_name: string;
|
full_name: string;
|
||||||
@@ -23,8 +33,9 @@ export interface CreateChoreRequest {
|
|||||||
title: string;
|
title: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
room: string;
|
room: string;
|
||||||
frequency: 'daily' | 'weekly' | 'monthly' | 'once';
|
frequency: 'daily' | 'weekly' | 'fortnightly' | 'monthly' | 'on_trigger';
|
||||||
assigned_to?: number;
|
points?: number;
|
||||||
|
assigned_user_ids?: number[]; // Multiple users
|
||||||
due_date?: string;
|
due_date?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,15 +43,16 @@ export interface UpdateChoreRequest {
|
|||||||
title?: string;
|
title?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
room?: string;
|
room?: string;
|
||||||
frequency?: 'daily' | 'weekly' | 'monthly' | 'once';
|
frequency?: 'daily' | 'weekly' | 'fortnightly' | 'monthly' | 'on_trigger';
|
||||||
|
points?: number;
|
||||||
status?: 'pending' | 'in_progress' | 'completed' | 'skipped';
|
status?: 'pending' | 'in_progress' | 'completed' | 'skipped';
|
||||||
assigned_to?: number;
|
assigned_user_ids?: number[]; // Multiple users
|
||||||
due_date?: string;
|
due_date?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const choreService = {
|
export const choreService = {
|
||||||
async getChores(): Promise<Chore[]> {
|
async getChores(params?: { user_id?: number; exclude_birthdays?: boolean }): Promise<Chore[]> {
|
||||||
const response = await api.get<Chore[]>('/api/v1/chores');
|
const response = await api.get<Chore[]>('/api/v1/chores', { params });
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -69,4 +81,9 @@ export const choreService = {
|
|||||||
});
|
});
|
||||||
return response.data;
|
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