File size: 1,773 Bytes
dfb3d07
 
de1f2ba
dfb3d07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a35ae1c
dfb3d07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { ExtractionResult, AssessmentResult } from "./types"

const BASE = process.env.NEXT_PUBLIC_API_URL ?? "/api"

export async function uploadFile(
  endpoint: "jd" | "resume",
  file: File
): Promise<{ text: string; filename: string }> {
  const formData = new FormData()
  formData.append("file", file)
  const res = await fetch(`${BASE}/upload/${endpoint}`, {
    method: "POST",
    body: formData,
  })
  if (!res.ok) throw new Error(`Upload failed: ${res.statusText}`)
  return res.json()
}

export async function startAssessment(
  jdText: string,
  resumeText: string,
  hoursPerDay: number,
  assessmentId?: string
): Promise<{ assessment_id: string; extraction: ExtractionResult }> {
  const res = await fetch(`${BASE}/assess`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ jd_text: jdText, resume_text: resumeText, hours_per_day: hoursPerDay, assessment_id: assessmentId })
  })
  if (!res.ok) throw new Error(`Failed to start assessment: ${res.statusText}`)
  return res.json()
}

export async function submitAnswer(
  assessmentId: string,
  answer: string
): Promise<void> {
  const res = await fetch(`${BASE}/assess/${assessmentId}/answer?answer=${encodeURIComponent(answer)}`, {
    method: "POST",
  })
  if (!res.ok) throw new Error(`Failed to submit answer: ${res.statusText}`)
}

export async function getRoadmap(
  assessmentId: string,
  hoursPerDay: number
): Promise<AssessmentResult> {
  const res = await fetch(`${BASE}/roadmap/${assessmentId}?hours_per_day=${hoursPerDay}`)
  if (!res.ok) throw new Error(`Failed to fetch roadmap: ${res.statusText}`)
  return res.json()
}

export function getStreamUrl(assessmentId: string): string {
  return `${BASE}/assess/${assessmentId}/stream`
}