-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassessments.ts
More file actions
94 lines (78 loc) · 2.33 KB
/
assessments.ts
File metadata and controls
94 lines (78 loc) · 2.33 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { type Application } from '@/generated/prisma';
import { type AssessmentStatus } from '@/generated/prisma';
import { type Assessment, type UpdateAssessmentDTO } from '@/lib/schemas/assessment.schema';
import { type AssessmentWithRelations } from '@/lib/types/assessment.types';
/**
* GET /api/assessments/:assessmentId
*/
export async function getAssessment(assessmentId: string): Promise<AssessmentWithRelations> {
const res = await fetch(`/api/assessments/${assessmentId}`);
const json = await res.json();
if (!res.ok) {
throw new Error(json.message);
}
return json.data;
}
/**
* PUT /api/assessments/:assessmentId
*/
export async function updateAssessment(payload: UpdateAssessmentDTO): Promise<Assessment> {
const res = await fetch(`/api/assessments/${payload.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
const json = await res.json();
if (!res.ok) {
throw new Error(json.message);
}
return json.data;
}
/**
* PUT /api/assessments/:assessmentId/status
*/
export async function updateAssessmentStatus(
assessmentId: string,
status: AssessmentStatus
): Promise<Application> {
const res = await fetch(`/api/assessments/${assessmentId}/status`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
assessmentStatus: status,
}),
});
const json = await res.json();
if (!res.ok) {
throw new Error(json.message);
}
return json.data;
}
/**
* POST /api/assessments/send-invitation
* Sends an assessment invitation email to a candidate
*/
export async function sendAssessmentInvitation(candidateId: string): Promise<{
success: boolean;
message: string;
candidateName: string;
positionTitle: string;
assessmentId: string;
}> {
const res = await fetch('/api/assessments/send-invitation', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ candidateId }),
});
const json = await res.json();
if (!res.ok) {
throw new Error(json.error ?? json.message ?? 'Failed to send assessment invitation');
}
return json.data;
}