Files
shadow-gunbuilder-ai-proto/lib/api/emailRequests.ts
T
2026-01-23 21:40:16 -05:00

82 lines
2.0 KiB
TypeScript

export interface EmailRequest {
id: number;
recipient: string;
email: string;
status: string;
createdAt: string;
updatedAt: string;
}
export interface CreateEmailRequestDto {
email: string;
status?: string;
}
export interface UpdateEmailRequestDto {
email?: string;
status?: string;
}
const API_BASE = process.env.NEXT_PUBLIC_API_BASE_URL || '';
export async function fetchEmailRequests(token: string): Promise<EmailRequest[]> {
const response = await fetch(`${API_BASE}/api/email`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (!response.ok) {
throw new Error(`Failed to fetch email requests: ${response.statusText}`);
}
return response.json();
}
export async function createEmailRequest(token: string, data: CreateEmailRequestDto): Promise<EmailRequest> {
const response = await fetch(`${API_BASE}/api/email`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Failed to create email request: ${response.statusText}`);
}
return response.json();
}
export async function updateEmailRequest(token: string, id: number, data: UpdateEmailRequestDto): Promise<EmailRequest> {
const response = await fetch(`${API_BASE}/api/email/${id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Failed to update email request: ${response.statusText}`);
}
return response.json();
}
export async function deleteEmailRequest(token: string, id: number): Promise<void> {
const response = await fetch(`${API_BASE}/api/email/${id}`, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${token}`,
},
});
if (!response.ok) {
throw new Error(`Failed to delete email request: ${response.statusText}`);
}
}