feat(api): add submitCompanyProfileWithDocuments helper for wizard
Some checks failed
build-and-release / build (push) Failing after 1m7s
Some checks failed
build-and-release / build (push) Failing after 1m7s
This commit is contained in:
parent
158c947944
commit
ec4bb48358
1 changed files with 33 additions and 0 deletions
|
|
@ -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) : {};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue