feat: migrate comprehensive venue module
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { request } from './request'
|
||||
import { compactParams, toArray, toNumber, toPageQuery, toPagination } from './mappers'
|
||||
|
||||
const toCourseCourt = (backendCourt = {}) => ({
|
||||
id: backendCourt.id ?? null,
|
||||
name: backendCourt.name || '',
|
||||
court_type: backendCourt.court_type || '',
|
||||
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 || ''
|
||||
})
|
||||
|
||||
const toCourseQuery = (params = {}) => compactParams({
|
||||
...toPageQuery(params),
|
||||
date: params.date,
|
||||
coach_id: params.coachId || params.coach_id,
|
||||
court_type: params.courtType || params.court_type
|
||||
})
|
||||
|
||||
export const courseApi = {
|
||||
getCourses(params = {}) {
|
||||
return request({
|
||||
url: '/api/courses',
|
||||
data: toCourseQuery(params)
|
||||
}).then((data) => toPagination(data, toCourse))
|
||||
},
|
||||
getCourseDetail(id) {
|
||||
return request({
|
||||
url: `/api/courses/${id}`
|
||||
}).then(toCourse)
|
||||
},
|
||||
createCourseBooking(courseId) {
|
||||
return request({
|
||||
url: '/api/bookings/course',
|
||||
method: 'POST',
|
||||
data: { course_id: courseId }
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user