mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-07 16:18:57 +00:00
63 lines
2.1 KiB
TypeScript
63 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 };
|
||
|
|
},
|
||
|
|
};
|