Files
HexaHost-GameCloud/apps/web/src/lib/api/schedules.ts

79 lines
1.7 KiB
TypeScript

import { apiFetch } from "./auth";
export type ScheduleTaskType =
| "START"
| "STOP"
| "RESTART"
| "BACKUP"
| "CONSOLE_COMMAND"
| "UPDATE_CHECK"
| "MAINTENANCE";
export interface ScheduledTask {
id: string;
taskType: ScheduleTaskType;
payload: Record<string, unknown> | null;
}
export interface Schedule {
id: string;
name: string;
timezone: string;
cronExpr: string;
enabled: boolean;
nextRunAt: string | null;
lastRunAt: string | null;
tasks: ScheduledTask[];
}
export interface ScheduleListResponse {
schedules: Schedule[];
}
export interface CreateSchedulePayload {
name: string;
timezone?: string;
cronExpr: string;
enabled?: boolean;
tasks: Array<{
taskType: ScheduleTaskType;
payload?: Record<string, unknown>;
}>;
}
export type UpdateSchedulePayload = Partial<CreateSchedulePayload>;
export async function listSchedules(serverId: string): Promise<ScheduleListResponse> {
return apiFetch<ScheduleListResponse>(`/servers/${serverId}/schedules`);
}
export async function createSchedule(
serverId: string,
payload: CreateSchedulePayload,
): Promise<Schedule> {
return apiFetch<Schedule>(`/servers/${serverId}/schedules`, {
method: "POST",
body: JSON.stringify(payload),
});
}
export async function updateSchedule(
serverId: string,
scheduleId: string,
payload: UpdateSchedulePayload,
): Promise<Schedule> {
return apiFetch<Schedule>(`/servers/${serverId}/schedules/${scheduleId}`, {
method: "PATCH",
body: JSON.stringify(payload),
});
}
export async function deleteSchedule(
serverId: string,
scheduleId: string,
): Promise<void> {
await apiFetch<void>(`/servers/${serverId}/schedules/${scheduleId}`, {
method: "DELETE",
});
}