54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
"use client"
|
|
|
|
export interface SkillAttemptPayload {
|
|
skillCode: string
|
|
promptLevel: number
|
|
correct: boolean
|
|
responseMs: number
|
|
}
|
|
|
|
export interface SessionPayload {
|
|
childId: string
|
|
startedAt: string
|
|
endedAt: string
|
|
durationSec: number
|
|
skillsPracticed: string
|
|
attempts: SkillAttemptPayload[]
|
|
}
|
|
|
|
export async function syncSession(payload: SessionPayload): Promise<string | null> {
|
|
try {
|
|
const res = await fetch("/api/sessions/sync", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
childId: payload.childId,
|
|
session: {
|
|
startedAt: payload.startedAt,
|
|
endedAt: payload.endedAt,
|
|
durationSec: payload.durationSec,
|
|
skillsPracticed: payload.skillsPracticed,
|
|
},
|
|
attempts: payload.attempts,
|
|
}),
|
|
})
|
|
const data = await res.json()
|
|
return data.sessionId ?? null
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export async function createMilestone(childId: string, skillCode: string): Promise<boolean> {
|
|
try {
|
|
const res = await fetch("/api/milestones", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ childId, skillCode }),
|
|
})
|
|
return res.ok
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|