fixes to admin using client fetch
CI / test (push) Successful in 7s

This commit is contained in:
2026-01-29 21:52:12 -05:00
parent a13687635b
commit 45270f9b18
22 changed files with 828 additions and 52 deletions
+13 -16
View File
@@ -14,9 +14,6 @@ export type CreatePlatformDto = {
export type UpdatePlatformDto = Partial<CreatePlatformDto>;
const API_BASE =
process.env.NEXT_PUBLIC_API_BASE_URL ?? "";
function normalizePlatform(raw: any): Platform {
const id = Number(raw?.id);
const key = String(raw?.key ?? "").trim();
@@ -33,9 +30,9 @@ function normalizePlatform(raw: any): Platform {
return { id, key, label, isActive };
}
export async function fetchPlatforms(tokenHeaders: HeadersInit): Promise<Platform[]> {
const res = await fetch(`${API_BASE}/api/platforms`, {
headers: { ...tokenHeaders },
export async function fetchPlatforms(_tokenHeaders: HeadersInit): Promise<Platform[]> {
const res = await fetch('/api/admin/platforms', {
credentials: 'include',
});
if (!res.ok) {
@@ -48,15 +45,15 @@ export async function fetchPlatforms(tokenHeaders: HeadersInit): Promise<Platfor
}
export async function createPlatform(
tokenHeaders: HeadersInit,
_tokenHeaders: HeadersInit,
dto: CreatePlatformDto
): Promise<Platform> {
const res = await fetch(`${API_BASE}/api/platforms`, {
const res = await fetch('/api/admin/platforms', {
method: "POST",
headers: {
"Content-Type": "application/json",
...tokenHeaders,
},
credentials: 'include',
body: JSON.stringify(dto),
});
@@ -69,17 +66,17 @@ export async function createPlatform(
}
export async function updatePlatform(
tokenHeaders: HeadersInit,
_tokenHeaders: HeadersInit,
id: number,
dto: UpdatePlatformDto
): Promise<Platform> {
const res = await fetch(`${API_BASE}/api/platforms/${id}`, {
const res = await fetch(`/api/admin/platforms/${id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
...tokenHeaders,
},
body: JSON.stringify({ isActive: dto.isActive }),
credentials: 'include',
body: JSON.stringify(dto),
});
if (!res.ok) {
@@ -90,10 +87,10 @@ export async function updatePlatform(
return normalizePlatform(await res.json());
}
export async function deletePlatform(tokenHeaders: HeadersInit, id: number): Promise<void> {
const res = await fetch(`${API_BASE}/api/platforms/${id}`, {
export async function deletePlatform(_tokenHeaders: HeadersInit, id: number): Promise<void> {
const res = await fetch(`/api/admin/platforms/${id}`, {
method: "DELETE",
headers: { ...tokenHeaders },
credentials: 'include',
});
if (!res.ok) {