Files
romm/frontend/src/services/api/platform.ts
Georges-Antoine Assi 389e768ee8 cleanup
2026-07-20 19:04:59 -04:00

60 lines
1.4 KiB
TypeScript

import type {
Body_add_platform_api_platforms_post as AddPlatformInput,
Body_update_platform_api_platforms__id__put as UpdatePlatformInput,
PlatformSchema,
} from "@/__generated__";
import api from "@/services/api";
type Platform = PlatformSchema;
export const platformApi = api;
async function uploadPlatform({ fsSlug }: { fsSlug: string }) {
const payload: AddPlatformInput = { fs_slug: fsSlug };
return api.post<Platform>("/platforms", payload);
}
async function getPlatforms() {
return api.get<Platform[]>("/platforms");
}
async function getPlatform(id: number | undefined) {
return api.get<Platform>(`/platforms/${id}`);
}
async function getSupportedPlatforms() {
return api.get<Platform[]>("/platforms/supported");
}
async function getFilesystemPlatforms() {
return api.get<Platform[]>("/platforms/filesystem");
}
async function updatePlatform({
platform,
description,
}: {
platform: Platform;
description?: string;
}) {
const payload: UpdatePlatformInput = {
custom_name: platform.custom_name,
...(description !== undefined ? { description } : {}),
};
return api.put<Platform>(`/platforms/${platform.id}`, payload);
}
async function deletePlatform({ platform }: { platform: Platform }) {
return api.delete(`/platforms/${platform.id}`);
}
export default {
uploadPlatform,
getPlatforms,
getPlatform,
getSupportedPlatforms,
getFilesystemPlatforms,
updatePlatform,
deletePlatform,
};