fix(courses): normalize "my courses" list response and cover image
The list query returned the raw paginated payload unmapped, so current/ended filtering and pagination metadata didn't work; align it with the same coverUrl fallback the detail query already used.
This commit is contained in:
@@ -8,15 +8,22 @@ export const studentCoursesKeys = {
|
||||
detail: (id) => ['student', 'courses', 'detail', id],
|
||||
}
|
||||
|
||||
const withCoverImage = (course) => ({
|
||||
...course,
|
||||
image: course.image ?? course.coverUrl ?? null,
|
||||
})
|
||||
|
||||
const adaptCourseResponse = (response) => {
|
||||
const course = response?.data ?? response
|
||||
if (!course) return course
|
||||
return {
|
||||
...course,
|
||||
image: course.image ?? course.coverUrl ?? null,
|
||||
}
|
||||
return withCoverImage(course)
|
||||
}
|
||||
|
||||
const adaptCourseListResponse = (response) => ({
|
||||
data: (response?.data?.items ?? response?.data ?? []).map((course) => withCoverImage(course)),
|
||||
meta: response?.data?.meta ?? response?.meta,
|
||||
})
|
||||
|
||||
export const useStudentCoursesListQuery = (filtersRef, paginationRef, options = {}) =>
|
||||
useQuery({
|
||||
queryKey: ['student', 'courses', 'list', filtersRef, paginationRef],
|
||||
@@ -25,6 +32,7 @@ export const useStudentCoursesListQuery = (filtersRef, paginationRef, options =
|
||||
...cleanFilters(filtersRef.value),
|
||||
...paginationRef.value,
|
||||
}),
|
||||
select: adaptCourseListResponse,
|
||||
...options,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user