@@ -13,13 +13,14 @@ import { refreshDbInternal } from '@/actions/refresh-db';
1313
1414const LOCAL_CMS_PROVIDER = process . env . LOCAL_CMS_PROVIDER ;
1515const COHORT_3_PARENT_COURSES = [ 8 , 9 , 10 , 11 , 12 ] ;
16+ const COHORT_4_PARENT_COURSES = [ 25 , 26 , 27 , 28 ]
1617// 8 -> Web + Devops + Web3
1718// 9 -> Web + Devops
1819// 10 -> Web3
1920// 11 -> Web
2021// 12 -> Devops
2122
22- export const APPX_COURSE_IDS = [ 1 , 2 , 3 , 8 , 9 , 10 , 11 , 12 ] ;
23+ export const APPX_COURSE_IDS = [ 1 , 2 , 3 , 8 , 9 , 10 , 11 , 12 , 25 , 26 , 27 , 28 ] ;
2324
2425function getExtraCourses ( currentCourses : Course [ ] , allCourses : Course [ ] ) {
2526 const hasCohort2 = currentCourses
@@ -30,57 +31,100 @@ function getExtraCourses(currentCourses: Course[], allCourses: Course[]) {
3031 COHORT_3_PARENT_COURSES . map ( ( x ) => x . toString ( ) ) . includes ( x . id . toString ( ) ) ,
3132 ) ;
3233
34+ const hasCohort4 = currentCourses . find ( ( x ) => COHORT_4_PARENT_COURSES . map ( ( y ) => y . toString ( ) ) . includes ( x . id . toString ( ) ) ) ;
35+
3336 let initialCourses : Course [ ] = [ ] ;
3437
3538 if ( hasCohort2 ) {
3639 initialCourses = [ ...allCourses . filter ( ( x ) => x . openToEveryone ) ] ;
37- } else if ( hasCohort3 ) {
40+ } else if ( hasCohort3 || hasCohort4 ) {
3841 initialCourses = [ ...allCourses . filter ( ( x ) => x . id === 7 || x . id === 4 ) ] ;
3942 }
4043
4144 // We break down parent courses into child courses
4245 // for eg, (web dev + devops) breaks down to web dev and devops
43- if ( ! hasCohort3 ) return initialCourses ;
46+ if ( ! hasCohort3 && ! hasCohort4 ) return initialCourses ;
47+ let userCourses : Course [ ] = [ ] ;
48+ userCourses = [ ...initialCourses ] ;
49+
50+ if ( hasCohort3 ) {
51+ let hasWebDev = false ;
52+ let hasDevOps = false ;
53+ let hasWeb3 = false ;
54+ if ( currentCourses . find ( ( x ) => x . id === 8 ) ) {
55+ hasWebDev = true ;
56+ hasDevOps = true ;
57+ hasWeb3 = true ;
58+ }
4459
45- const userCourses = [ ...initialCourses ] ;
60+ if ( currentCourses . find ( ( x ) => x . id === 9 ) ) {
61+ hasWebDev = true ;
62+ hasDevOps = true ;
63+ }
4664
47- let hasWebDev = false ;
48- let hasDevOps = false ;
49- let hasWeb3 = false ;
50- if ( currentCourses . find ( ( x ) => x . id === 8 ) ) {
51- hasWebDev = true ;
52- hasDevOps = true ;
53- hasWeb3 = true ;
54- }
65+ if ( currentCourses . find ( ( x ) => x . id === 10 ) ) {
66+ hasWeb3 = true ;
67+ }
5568
56- if ( currentCourses . find ( ( x ) => x . id === 9 ) ) {
57- hasWebDev = true ;
58- hasDevOps = true ;
59- }
69+ if ( currentCourses . find ( ( x ) => x . id === 11 ) ) {
70+ hasWebDev = true ;
71+ }
6072
61- if ( currentCourses . find ( ( x ) => x . id === 10 ) ) {
62- hasWeb3 = true ;
63- }
73+ if ( currentCourses . find ( ( x ) => x . id === 12 ) ) {
74+ hasDevOps = true ;
75+ }
6476
65- if ( currentCourses . find ( ( x ) => x . id === 11 ) ) {
66- hasWebDev = true ;
67- }
77+ if ( hasWebDev ) {
78+ userCourses . push ( allCourses . find ( ( x ) => x . id === 14 ) ! ) ;
79+ }
6880
69- if ( currentCourses . find ( ( x ) => x . id === 12 ) ) {
70- hasDevOps = true ;
71- }
81+ if ( hasDevOps ) {
82+ userCourses . push ( allCourses . find ( ( x ) => x . id === 15 ) ! ) ;
83+ }
7284
73- if ( hasWebDev ) {
74- userCourses . push ( allCourses . find ( ( x ) => x . id === 14 ) ! ) ;
85+ if ( hasWeb3 ) {
86+ userCourses . push ( allCourses . find ( ( x ) => x . id === 13 ) ! ) ;
87+ userCourses . push ( allCourses . find ( ( x ) => x . id === 20 ) ! ) ;
88+ }
7589 }
7690
77- if ( hasDevOps ) {
78- userCourses . push ( allCourses . find ( ( x ) => x . id === 15 ) ! ) ;
79- }
91+ if ( hasCohort4 ) {
92+ let hasWebDev = false ;
93+ let hasAi = false ;
94+ let hasWeb3 = false ;
95+ if ( currentCourses . find ( ( x ) => x . id === 24 ) ) {
96+ hasWebDev = true ;
97+ hasAi = true ;
98+ hasWeb3 = true ;
99+ }
100+
101+ if ( currentCourses . find ( ( x ) => x . id === 25 ) ) {
102+ hasWebDev = true ;
103+ }
104+
105+ if ( currentCourses . find ( ( x ) => x . id === 27 ) ) {
106+ hasAi = true ;
107+ }
108+
109+ if ( currentCourses . find ( ( x ) => x . id === 26 ) ) {
110+ hasWeb3 = true ;
111+ }
80112
81- if ( hasWeb3 ) {
82- userCourses . push ( allCourses . find ( ( x ) => x . id === 13 ) ! ) ;
83- userCourses . push ( allCourses . find ( ( x ) => x . id === 20 ) ! ) ;
113+ if ( hasWebDev ) {
114+ userCourses . push ( allCourses . find ( ( x ) => x . id === 21 ) ! ) ;
115+ }
116+
117+ if ( hasAi ) {
118+ userCourses . push ( allCourses . find ( ( x ) => x . id === 23 ) ! ) ;
119+ }
120+
121+ if ( hasWeb3 ) {
122+ userCourses . push ( allCourses . find ( ( x ) => x . id === 22 ) ! ) ;
123+ }
124+
125+ if ( hasWeb3 || hasAi || hasWebDev ) {
126+ userCourses . push ( allCourses . find ( ( x ) => x . id === 24 ) ! ) ;
127+ }
84128 }
85129
86130 return userCourses ;
@@ -169,7 +213,8 @@ export async function getPurchases(email: string): Promise<CoursesResponse> {
169213 ...getExtraCourses ( coursesFromDb , courses ) ,
170214 ]
171215 . filter ( ( x ) => x . id )
172- . filter ( ( x ) => ! COHORT_3_PARENT_COURSES . includes ( x . id ) ) ;
216+ . filter ( ( x ) => ! COHORT_3_PARENT_COURSES . includes ( x . id ) )
217+ . filter ( ( x ) => ! COHORT_4_PARENT_COURSES . includes ( x . id ) ) ;
173218 cache . set ( 'courses' , [ email ] , allCourses , 60 * 60 ) ;
174219 return {
175220 type : 'success' ,
@@ -202,6 +247,7 @@ export async function getPurchases(email: string): Promise<CoursesResponse> {
202247
203248 // Remove the parent courses, child courses already added in getExtraCourses
204249 responses . filter ( ( x ) => ! COHORT_3_PARENT_COURSES . includes ( x . id ) ) ;
250+ responses . filter ( ( x ) => ! COHORT_4_PARENT_COURSES . includes ( x . id ) ) ;
205251
206252 cache . set ( 'courses' , [ email ] , responses , 60 * 60 * 24 ) ;
207253 refreshDbInternal ( session ?. user . id , session ?. user . email ) ;
@@ -239,6 +285,10 @@ export async function getAppxCourseId(courseId: string) {
239285 13 : [ '8' , '10' ] ,
240286 14 : [ '8' , '9' , '11' ] ,
241287 15 : [ '8' , '9' , '12' ] ,
288+ 21 : [ '28' , '25' ] ,
289+ 22 : [ '26' , '25' ] ,
290+ 23 : [ '27' , '25' ] ,
291+ 24 : [ '28' , '25' , '26' , '27' ] ,
242292 } ;
243293
244294 let appxCourseId : string | null = null ;
0 commit comments