mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-07 16:18:57 +00:00
Additive-only: pages still use lib/api/* and constants/queryKeys.ts until the page-migration agents run. Each domain ships api.ts (HTTP moved from lib/api), types.ts (contract re-exports + view types), schemas.ts (contract schema re-exports + form schemas with toRequest mappers), and use-cases.ts (TanStack Query v5 hooks + hierarchical query keys, mirroring current page invalidations and toast-on-error behavior). Adds an explicit vite/vitest alias for the @proposal-system/api-contracts/schemas subpath (package has no exports map) plus a schema/mapper smoke test suite.
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
// Admin domain — HTTP calls only (no hooks). Moved from lib/api/admin.ts.
|
|
import apiClient from '../../lib/api/client';
|
|
import type { ProposalDetail } from '../proposals/types';
|
|
import type { DashboardStats, UpdateProposalRequest, AuditEntry, SimilarProposal } from './types';
|
|
|
|
export const adminApi = {
|
|
getDashboard: async (): Promise<DashboardStats> => {
|
|
const res = await apiClient.get('/admin/dashboard');
|
|
return res.data;
|
|
},
|
|
|
|
updateProposal: async (id: string, data: UpdateProposalRequest): Promise<void> => {
|
|
await apiClient.put(`/proposals/${id}`, data);
|
|
},
|
|
|
|
approveProposal: async (id: string): Promise<void> => {
|
|
await apiClient.post(`/proposals/${id}/approve`);
|
|
},
|
|
|
|
returnToReview: async (id: string): Promise<void> => {
|
|
await apiClient.post(`/proposals/${id}/return-to-review`);
|
|
},
|
|
|
|
sendProposal: async (id: string): Promise<void> => {
|
|
await apiClient.post(`/proposals/${id}/send`);
|
|
},
|
|
|
|
reviseProposal: async (id: string): Promise<void> => {
|
|
await apiClient.post(`/proposals/${id}/revise`);
|
|
},
|
|
|
|
getHistory: async (id: string): Promise<ProposalDetail[]> => {
|
|
const res = await apiClient.get(`/proposals/${id}/history`);
|
|
return res.data;
|
|
},
|
|
|
|
getAudit: async (id: string): Promise<AuditEntry[]> => {
|
|
const res = await apiClient.get(`/proposals/${id}/audit`);
|
|
return res.data;
|
|
},
|
|
|
|
generateSuggestions: async (id: string): Promise<void> => {
|
|
await apiClient.post(`/proposals/${id}/generate-suggestions`);
|
|
},
|
|
|
|
getSimilar: async (id: string): Promise<SimilarProposal[]> => {
|
|
const res = await apiClient.get(`/proposals/${id}/similar`);
|
|
return res.data;
|
|
},
|
|
|
|
getPdf: async (id: string, regenerate = false): Promise<{ downloadUrl: string } | null> => {
|
|
const params = regenerate ? '?regenerate=true' : '';
|
|
const res = await apiClient.get(`/proposals/${id}/pdf${params}`, {
|
|
responseType: 'blob',
|
|
validateStatus: (status) => status < 500,
|
|
});
|
|
if (res.status === 202) return null;
|
|
const blob = res.data as Blob;
|
|
const downloadUrl = URL.createObjectURL(blob);
|
|
return { downloadUrl };
|
|
},
|
|
};
|