-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathopening.ts
More file actions
33 lines (28 loc) · 767 Bytes
/
opening.ts
File metadata and controls
33 lines (28 loc) · 767 Bytes
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
import { buildUrl } from '../utils'
// API Types for opening drill logging
export interface LogOpeningDrillRequest {
opening_fen: string
side_played: string
opponent: string
num_moves: number
moves_played_uci: string[]
}
// API function to log a completed opening drill
export const logOpeningDrill = async (
request: LogOpeningDrillRequest,
): Promise<void> => {
const res = await fetch(buildUrl('opening/log_opening_drill'), {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(request),
})
if (res.status === 401) {
throw new Error('Unauthorized')
}
if (!res.ok) {
throw new Error(`Failed to log opening drill: ${res.statusText}`)
}
}