+13
-16
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user