File size: 895 Bytes
ac717a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const API = '/api/interview';

export async function startInterview(role, difficulty, interviewType, questionCount) {
  const res = await fetch(`${API}/start`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ role, difficulty, interviewType, questionCount }),
  });
  if (!res.ok) throw new Error((await res.json()).error);
  return res.json();
}

export async function submitAnswer(sessionId, answer) {
  const res = await fetch(`${API}/answer`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ sessionId, answer }),
  });
  if (!res.ok) throw new Error((await res.json()).error);
  return res.json();
}

export async function getReport(sessionId) {
  const res = await fetch(`${API}/report/${sessionId}`);
  if (!res.ok) throw new Error((await res.json()).error);
  return res.json();
}