1414 * limitations under the License.
1515 */
1616
17+ import { PAGE_SIZE } from '@/constants/config' ;
1718import { merge } from '@/utils' ;
1819import httpClient , { legacyClient , mergeMultipleResponses } from '@/utils/http' ;
1920
2021import { fetchPermission , fetchLessonDetail } from '../course/repository' ;
2122
23+ async function fetchList ( params = { } ) {
24+ const { sort, ...others } = params ;
25+
26+ return legacyClient . get ( '/learn/course/challenges' , {
27+ params : merge ( { take : PAGE_SIZE } , others , {
28+ order : sort || 'default' ,
29+ } ) ,
30+ } ) ;
31+ }
32+
2233async function fetchOne ( id ) {
2334 return legacyClient . get ( `/learn/course/challenges/${ id } ` ) ;
2435}
2536
37+ async function enrollOne ( id , data ) {
38+ return httpClient . post ( `/learn/general/course/challenges/${ id } /permission/enrool` , data ) ;
39+ }
40+
2641async function fetchOneWithPermission ( id ) {
2742 return mergeMultipleResponses ( [ fetchOne ( id ) , fetchPermission ( id ) ] , ( [ { data, ...others } , permission ] ) => ( {
2843 ...others ,
@@ -37,29 +52,30 @@ async function fetchLessonWithEntity({ id, entityId }) {
3752 } ) ) ;
3853}
3954
40- async function fetchPublishedChallengeList ( params = { } ) {
41- const { userId, sort, ...others } = params ;
55+ async function fetchRelatedCourse ( id ) {
56+ return httpClient . get ( `/learn/general/course/challenges/${ id } /link` ) ;
57+ }
4258
43- return legacyClient . get ( '/learn/course/challenges' , {
44- params : merge ( { take : 20 } , others , {
45- team_uid : userId ,
46- order : sort || 'default' ,
47- } ) ,
48- } ) ;
59+ async function fetchPublishedChallengeList ( params = { } ) {
60+ return fetchList ( { ...params , team_uid : params . userId } ) ;
4961}
5062
5163async function fetchEnrolledChallengeList ( params = { } ) {
5264 const { userId, sort, ...others } = params ;
5365
5466 return legacyClient . get ( '/learn/dashboard/public/enrool/series' , {
55- params : merge ( { take : 20 } , others , {
67+ params : merge ( { take : PAGE_SIZE } , others , {
5668 id : userId ,
5769 series_type : 'challenges' ,
5870 order : sort || 'default' ,
5971 } ) ,
6072 } ) ;
6173}
6274
75+ async function updateTransaction ( id , data ) {
76+ return httpClient . post ( `/learn/general/course/challenges/${ id } /permission/pay` , data ) ;
77+ }
78+
6379async function updateMultipleApplicantStatus ( id , { userIds, status } ) {
6480 return httpClient . post ( `/learn/creator/series/${ id } /batch/enrool/status` , { uids : userIds , status } ) ;
6581}
@@ -79,8 +95,9 @@ async function updateEmailTemplate(id, { title, body }) {
7995}
8096
8197export {
82- fetchOne , fetchOneWithPermission , fetchLessonWithEntity ,
98+ fetchList , fetchOne , enrollOne ,
99+ fetchOneWithPermission , fetchLessonWithEntity , fetchRelatedCourse ,
83100 fetchPublishedChallengeList , fetchEnrolledChallengeList ,
84- updateMultipleApplicantStatus ,
101+ updateTransaction , updateMultipleApplicantStatus ,
85102 fetchEmailTemplate , updateEmailTemplate ,
86103} ;
0 commit comments