Public Access
Release Pipeline / build-and-release (push) Failing after 41s
- Implemented MyExams component for managing user exams, including loading, deleting, and creating new exams. - Created MyResults component to display user results with options to review and delete results. - Developed Settings component for updating user display name and changing password. - Introduced Workspace component to serve as a container for MyExams, MyResults, and Settings, with navigation between tabs.
27 lines
872 B
TypeScript
27 lines
872 B
TypeScript
import type { Exam } from '../types'
|
|
|
|
export const validateExam = (data: unknown): string | null => {
|
|
if (!data || typeof data !== 'object') return 'Not a JSON object'
|
|
const d = data as Record<string, unknown>
|
|
if (!d['title']) return 'Missing "title"'
|
|
if (!Array.isArray(d['questions']) || d['questions'].length === 0) return 'Missing "questions" array'
|
|
for (const q of d['questions'] as Record<string, unknown>[]) {
|
|
if (!q['id']) return 'Question missing id'
|
|
if (!q['type']) return `Question "${String(q['id'])}" missing type`
|
|
if (!q['prompt']) return `Question "${String(q['id'])}" missing prompt`
|
|
}
|
|
return null
|
|
}
|
|
|
|
function generateId(): string {
|
|
return Math.random().toString(36).slice(2, 10)
|
|
}
|
|
|
|
export const parseExam = (data: unknown): Exam => {
|
|
const exam = data as Exam
|
|
if (!exam.id) {
|
|
exam.id = generateId()
|
|
}
|
|
return exam
|
|
}
|