feat: migrate comprehensive courses to sessions
This commit is contained in:
@@ -8,27 +8,28 @@ const toCourseCourt = (backendCourt = {}) => ({
|
||||
court_type_label: backendCourt.court_type_label || ''
|
||||
})
|
||||
|
||||
export const toCourse = (backendCourse = {}) => ({
|
||||
id: backendCourse.id ?? null,
|
||||
title: backendCourse.title || '',
|
||||
cover_image: backendCourse.cover_image || '',
|
||||
coach_id: backendCourse.coach_id ?? null,
|
||||
coach_name: backendCourse.coach_name || '',
|
||||
start_at: backendCourse.start_at || '',
|
||||
end_at: backendCourse.end_at || '',
|
||||
capacity: toNumber(backendCourse.capacity),
|
||||
booked_count: toNumber(backendCourse.booked_count),
|
||||
remaining_count: toNumber(backendCourse.remaining_count),
|
||||
price: backendCourse.price || '0.00',
|
||||
status: backendCourse.status || '',
|
||||
status_label: backendCourse.status_label || backendCourse.status || '',
|
||||
courts: toArray(backendCourse.courts).map(toCourseCourt),
|
||||
detail_html: backendCourse.detail_html || '',
|
||||
created_at: backendCourse.created_at || '',
|
||||
updated_at: backendCourse.updated_at || ''
|
||||
export const toSession = (backendSession = {}) => ({
|
||||
id: backendSession.id ?? null,
|
||||
course_id: backendSession.course_id ?? null,
|
||||
title: backendSession.title || '',
|
||||
cover_image: backendSession.cover_image || '',
|
||||
coach_id: backendSession.coach_id ?? null,
|
||||
coach_name: backendSession.coach_name || '',
|
||||
start_at: backendSession.start_at || '',
|
||||
end_at: backendSession.end_at || '',
|
||||
capacity: toNumber(backendSession.capacity),
|
||||
booked_count: toNumber(backendSession.booked_count),
|
||||
remaining_count: toNumber(backendSession.remaining_count),
|
||||
price: backendSession.price || '0.00',
|
||||
status: backendSession.status || '',
|
||||
status_label: backendSession.status_label || backendSession.status || '',
|
||||
courts: toArray(backendSession.courts).map(toCourseCourt),
|
||||
detail_html: backendSession.detail_html || '',
|
||||
created_at: backendSession.created_at || '',
|
||||
updated_at: backendSession.updated_at || ''
|
||||
})
|
||||
|
||||
const toCourseQuery = (params = {}) => compactParams({
|
||||
const toSessionQuery = (params = {}) => compactParams({
|
||||
...toPageQuery(params),
|
||||
date: params.date,
|
||||
coach_id: params.coachId || params.coach_id,
|
||||
@@ -36,22 +37,22 @@ const toCourseQuery = (params = {}) => compactParams({
|
||||
})
|
||||
|
||||
export const courseApi = {
|
||||
getCourses(params = {}) {
|
||||
getSessions(params = {}) {
|
||||
return request({
|
||||
url: '/api/courses',
|
||||
data: toCourseQuery(params)
|
||||
}).then((data) => toPagination(data, toCourse))
|
||||
url: '/api/sessions',
|
||||
data: toSessionQuery(params)
|
||||
}).then((data) => toPagination(data, toSession))
|
||||
},
|
||||
getCourseDetail(id) {
|
||||
getSessionDetail(id) {
|
||||
return request({
|
||||
url: `/api/courses/${id}`
|
||||
}).then(toCourse)
|
||||
url: `/api/sessions/${id}`
|
||||
}).then(toSession)
|
||||
},
|
||||
createCourseBooking(courseId) {
|
||||
createCourseBooking(sessionId) {
|
||||
return request({
|
||||
url: '/api/bookings/course',
|
||||
method: 'POST',
|
||||
data: { course_id: courseId }
|
||||
data: { session_id: sessionId }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user