fixes to admin/products

This commit is contained in:
2026-01-09 10:18:32 -05:00
parent ae86fe6867
commit c509cb6cd0
9 changed files with 1061 additions and 368 deletions
+21 -3
View File
@@ -7,6 +7,9 @@ import type {
ProductVisibility,
} from "./types";
import type { CaliberDto } from "./types";
async function authedFetch(url: string, init?: RequestInit) {
const token = getToken();
const res = await fetch(url, {
@@ -30,11 +33,15 @@ export async function fetchAdminRoles(params: Record<string, any>) {
return (await res.json()) as string[];
}
export async function fetchAdminCalibers(params: Record<string, any>) {
// Facet/filtering can still use distinct values seen on products (optional)
export async function fetchProductCaliberFacet(params: Record<string, any>) {
const res = await authedFetch(
`${API_BASE}/api/v1/admin/products/calibers?${qs(params)}`
);
if (!res.ok) throw new Error(`Failed to load calibers (${res.status}): ${await res.text()}`);
if (!res.ok)
throw new Error(
`Failed to load caliber facet (${res.status}): ${await res.text()}`
);
return (await res.json()) as string[];
}
@@ -55,7 +62,7 @@ export async function fetchPlatforms() {
if (!res.ok) throw new Error(`Failed to load platforms (${res.status}): ${await res.text()}`);
const all = (await res.json()) as PlatformDto[];
return all.filter((p) => p.is_active);
return all.filter((p) => (p as any).is_active ?? (p as any).isActive);
}
export async function bulkUpdate(
@@ -92,4 +99,15 @@ export async function bulkUpdate(
if (!res.ok) throw new Error(`Bulk update failed (${res.status}): ${await res.text()}`);
return (await res.json()) as { updatedCount: number; skippedLockedCount: number };
}
export async function fetchAdminCalibers(params: Record<string, any>) {
const res = await authedFetch(
`${API_BASE}/api/v1/admin/calibers?${qs(params)}`
);
if (!res.ok) {
throw new Error(`Failed to load calibers (${res.status}): ${await res.text()}`);
}
return (await res.json()) as CaliberDto[];
}
+9
View File
@@ -58,4 +58,13 @@ export const initialFilters: AdminFilters = {
status: "",
builderEligible: "",
adminLocked: "",
};
export type CaliberDto = {
id: number;
key: string; // canonical key (ex: "5.56 NATO")
label: string; // human-readable label
isActive: boolean;
createdAt?: string;
updatedAt?: string;
};