feat(api): add submitCompanyProfileWithDocuments helper for wizard
Some checks failed
build-and-release / build (push) Failing after 1m7s

This commit is contained in:
Ashwin Kumar Sivakumar 2026-07-11 01:34:37 +05:30
parent 158c947944
commit ec4bb48358

View file

@ -238,3 +238,36 @@ export async function uploadDocument(rolePrefix: string, file: File, documentTyp
}
return res.json();
}
/**
* Submit a COMPANY profile + documents in a single multipart POST.
* Used by the 3-step wizard on the Company dashboard.
* Returns: { verification_id, status, documents_uploaded, documents_failed, storage_backend, document_errors? }
*/
export async function submitCompanyProfileWithDocuments(
profileData: Record<string, any>,
documents: Array<{ documentType: string; file: File }>
): Promise<any> {
const token = typeof window !== 'undefined'
? (sessionStorage.getItem('nxtgauge_access_token') || '')
: '';
const fd = new FormData();
fd.append('profile', JSON.stringify(profileData));
for (const { documentType, file } of documents) {
// Append a stable filename so the backend can derive document_type from the stem
fd.append('documents', file, `${documentType}_${file.name}`);
}
const res = await fetch(`${API}/api/companies/profile/submit-with-documents`, {
method: 'POST',
headers: token ? { Authorization: `Bearer ${token}` } : {},
credentials: 'include',
body: fd,
});
const text = await res.text().catch(() => '');
if (!res.ok) {
let msg = `Submit failed: ${res.status}`;
try { msg = JSON.parse(text).error || msg; } catch { /* keep default */ }
throw new Error(msg);
}
return text ? JSON.parse(text) : {};
}