feature: a minimal implementation of the appointment feature done.
This commit is contained in:
32
frontend/src/lib/api/appointments.ts
Normal file
32
frontend/src/lib/api/appointments.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { apiClient } from './client';
|
||||
import type { AppointmentColumnProvider, AppointmentRecord } from '@/types/appointment';
|
||||
|
||||
export interface CreateAppointmentBody {
|
||||
patientId: string;
|
||||
providerUserId: string;
|
||||
startAt: string;
|
||||
endAt: string;
|
||||
purpose: string;
|
||||
}
|
||||
|
||||
export const appointmentsApi = {
|
||||
columnProviders: async (): Promise<{ success: boolean; data: AppointmentColumnProvider[] }> => {
|
||||
const response = await apiClient.get('/appointments/column-providers');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
list: async (params: { from: string; to: string }): Promise<{ success: boolean; data: AppointmentRecord[] }> => {
|
||||
const response = await apiClient.get('/appointments', { params });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
create: async (body: CreateAppointmentBody): Promise<{ success: boolean; data: AppointmentRecord }> => {
|
||||
const response = await apiClient.post('/appointments', body);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
remove: async (id: string): Promise<{ success: boolean }> => {
|
||||
const response = await apiClient.delete(`/appointments/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
63
frontend/src/lib/appointmentTime.ts
Normal file
63
frontend/src/lib/appointmentTime.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/** Normalize to local midnight; invalid input falls back to today. */
|
||||
export function startOfLocalDay(d: Date): Date {
|
||||
if (Number.isNaN(d.getTime())) {
|
||||
const t = new Date();
|
||||
return new Date(t.getFullYear(), t.getMonth(), t.getDate(), 0, 0, 0, 0);
|
||||
}
|
||||
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/** Local calendar bounds for a date (browser timezone). */
|
||||
export function getLocalDayIsoRange(day: Date): { from: string; to: string } {
|
||||
const start = startOfLocalDay(day);
|
||||
const end = new Date(start.getFullYear(), start.getMonth(), start.getDate() + 1, 0, 0, 0, 0);
|
||||
return { from: start.toISOString(), to: end.toISOString() };
|
||||
}
|
||||
|
||||
export function toDateInputValue(d: Date): string {
|
||||
const y = d.getFullYear();
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${day}`;
|
||||
}
|
||||
|
||||
export function parseDateInput(value: string): Date {
|
||||
const [y, m, d] = value.split('-').map(Number);
|
||||
return new Date(y, m - 1, d, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
export function combineLocalDateAndTime(day: Date, timeHHmm: string): Date {
|
||||
const [h, min] = timeHHmm.split(':').map(Number);
|
||||
return new Date(day.getFullYear(), day.getMonth(), day.getDate(), h, min, 0, 0);
|
||||
}
|
||||
|
||||
export function formatTimeForInput(d: Date): string {
|
||||
const h = String(d.getHours()).padStart(2, '0');
|
||||
const m = String(d.getMinutes()).padStart(2, '0');
|
||||
return `${h}:${m}`;
|
||||
}
|
||||
|
||||
export function isSameLocalCalendarDay(a: Date, b: Date): boolean {
|
||||
return (
|
||||
a.getFullYear() === b.getFullYear() &&
|
||||
a.getMonth() === b.getMonth() &&
|
||||
a.getDate() === b.getDate()
|
||||
);
|
||||
}
|
||||
|
||||
export function formatHourLabel(hour: number): string {
|
||||
const d = new Date(2000, 0, 1, hour, 0, 0, 0);
|
||||
return d.toLocaleTimeString(undefined, { hour: 'numeric', hour12: true });
|
||||
}
|
||||
|
||||
/** Local midnight + delta calendar days. */
|
||||
export function addCalendarDays(day: Date, delta: number): Date {
|
||||
return new Date(day.getFullYear(), day.getMonth(), day.getDate() + delta, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/** Compare two calendar days at local midnight (ordering by date only). */
|
||||
export function compareLocalDayStart(a: Date, b: Date): number {
|
||||
const ta = new Date(a.getFullYear(), a.getMonth(), a.getDate()).getTime();
|
||||
const tb = new Date(b.getFullYear(), b.getMonth(), b.getDate()).getTime();
|
||||
return ta - tb;
|
||||
}
|
||||
12
frontend/src/lib/formatApiError.ts
Normal file
12
frontend/src/lib/formatApiError.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export function formatApiErrorMessage(err: unknown, fallback: string): string {
|
||||
if (err && typeof err === 'object' && 'message' in err) {
|
||||
const m = (err as { message: unknown }).message;
|
||||
if (Array.isArray(m)) {
|
||||
return m.filter(Boolean).join(', ');
|
||||
}
|
||||
if (typeof m === 'string' && m.trim()) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
Reference in New Issue
Block a user