Merge pull request 'Enhance appointment scheduling and rejection logic by refining payload structure. Default create_jitsi_meeting to true if not specified and remove undefined fields from the payload. Update scheduleAppointmentSchema to support optional date_str and time…' (#44) from feat/booking-panel into master
Reviewed-on: http://35.207.46.142/ATTUNE-HEART-THERAPY/website/pulls/44
This commit is contained in:
commit
9aefe892cf
@ -392,13 +392,27 @@ export async function scheduleAppointment(id: string, input: ScheduleAppointment
|
||||
throw new Error("Authentication required.");
|
||||
}
|
||||
|
||||
// Build payload with defaults
|
||||
const payload: any = {
|
||||
...input,
|
||||
// Default create_jitsi_meeting to true if not specified
|
||||
create_jitsi_meeting: input.create_jitsi_meeting !== undefined ? input.create_jitsi_meeting : true,
|
||||
};
|
||||
|
||||
// Remove undefined fields
|
||||
Object.keys(payload).forEach(key => {
|
||||
if (payload[key] === undefined) {
|
||||
delete payload[key];
|
||||
}
|
||||
});
|
||||
|
||||
const response = await fetch(`${API_ENDPOINTS.meetings.listAppointments}${id}/schedule/`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${tokens.access}`,
|
||||
},
|
||||
body: JSON.stringify(input),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
const data = await parseResponse(response);
|
||||
@ -415,13 +429,19 @@ export async function rejectAppointment(id: string, input: RejectAppointmentInpu
|
||||
throw new Error("Authentication required.");
|
||||
}
|
||||
|
||||
// Build payload - only include rejection_reason if provided
|
||||
const payload: any = {};
|
||||
if (input.rejection_reason) {
|
||||
payload.rejection_reason = input.rejection_reason;
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_ENDPOINTS.meetings.listAppointments}${id}/reject/`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${tokens.access}`,
|
||||
},
|
||||
body: JSON.stringify(input),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
const data = await parseResponse(response);
|
||||
|
||||
@ -36,10 +36,26 @@ export const createAppointmentSchema = z.object({
|
||||
export type CreateAppointmentInput = z.infer<typeof createAppointmentSchema>;
|
||||
|
||||
// Schedule Appointment Schema (Admin only)
|
||||
// Supports two scheduling methods:
|
||||
// 1. Direct datetime: scheduled_datetime + scheduled_duration
|
||||
// 2. Date and slot: date_str + time_slot + scheduled_duration
|
||||
export const scheduleAppointmentSchema = z.object({
|
||||
scheduled_datetime: z.string().datetime("Invalid datetime format"),
|
||||
scheduled_datetime: z.string().datetime("Invalid datetime format").optional(),
|
||||
scheduled_duration: z.number().int().positive().optional(),
|
||||
});
|
||||
date_str: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").optional(),
|
||||
time_slot: z.enum(["morning", "afternoon", "evening"]).optional(),
|
||||
create_jitsi_meeting: z.boolean().optional(),
|
||||
jitsi_custom_config: z.string().optional(),
|
||||
}).refine(
|
||||
(data) => {
|
||||
// Either scheduled_datetime OR (date_str + time_slot) must be provided
|
||||
return data.scheduled_datetime || (data.date_str && data.time_slot);
|
||||
},
|
||||
{
|
||||
message: "Either scheduled_datetime or both date_str and time_slot must be provided",
|
||||
path: ["scheduled_datetime"],
|
||||
}
|
||||
);
|
||||
|
||||
export type ScheduleAppointmentInput = z.infer<typeof scheduleAppointmentSchema>;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user