feat: add useCourse composable for managing course data, enrollment, and learning progress.
This commit is contained in:
parent
e705f2c6b9
commit
693b00b96a
1 changed files with 15 additions and 2 deletions
|
|
@ -91,8 +91,21 @@ export const useCourse = () => {
|
|||
} : {}
|
||||
})
|
||||
|
||||
// API returns data array even for single item based on schema
|
||||
const courseData = data.data?.[0]
|
||||
// API might return an array (list) or single object
|
||||
let courseData: any = null
|
||||
|
||||
if (Array.isArray(data.data)) {
|
||||
// Try to find the matching course ID in the array
|
||||
courseData = data.data.find((c: any) => c.id == id)
|
||||
|
||||
// Fallback: If not found, and array has length 1, it might be the one (if ID mismatch isn't the issue)
|
||||
// But generally, we should expect a match. If not match, maybe the API returned a generic list.
|
||||
if (!courseData && data.data.length === 1) {
|
||||
courseData = data.data[0]
|
||||
}
|
||||
} else {
|
||||
courseData = data.data
|
||||
}
|
||||
|
||||
if (!courseData) throw new Error('Course not found')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue