Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 01:35:06 +00:00
co-authored by renee-png
parent 5dbc839ebe
commit fe465b9e2b
+32 -3
View File
@@ -162,12 +162,13 @@ export async function savePdfToDocuments(opts: {
caseId: string;
name: string;
folder?: string;
mimeType?: string;
}) {
const { blob, caseId, name, folder = "Forms & Letters" } = opts;
const { blob, caseId, name, folder = "Forms & Letters", mimeType = "application/pdf" } = opts;
const path = `${caseId}/${Date.now()}-${name}`;
const { error: upErr } = await supabase.storage
.from("case-documents")
.upload(path, blob, { contentType: "application/pdf", upsert: false });
.upload(path, blob, { contentType: mimeType, upsert: false });
if (upErr) throw upErr;
const { data: u } = await supabase.auth.getUser();
const { error: insErr } = await supabase.from("documents").insert({
@@ -175,9 +176,37 @@ export async function savePdfToDocuments(opts: {
folder,
name,
storage_path: path,
mime_type: "application/pdf",
mime_type: mimeType,
size_bytes: blob.size,
uploaded_by: u.user?.id ?? null,
});
if (insErr) throw insErr;
}
export interface CaseLite {
id: string;
case_number: string;
title: string;
}
export async function fetchAccessibleCases(): Promise<CaseLite[]> {
const { data } = await supabase
.from("cases")
.select("id,case_number,title")
.order("opened_at", { ascending: false })
.limit(500);
return (data ?? []) as CaseLite[];
}
export async function fetchCaseCustomValues(caseId: string): Promise<Record<string, string>> {
const { data } = await supabase
.from("case_field_values")
.select("value, field:custom_case_fields(key)")
.eq("case_id", caseId);
const map: Record<string, string> = {};
(data ?? []).forEach((row: any) => {
const k = row.field?.key;
if (k) map[k] = row.value ?? "";
});
return map;
}