MCPcopy Create free account
hub / github.com/code100x/cms / getExtraCourses

Function getExtraCourses

src/utiles/appx.ts:25–131  ·  view source on GitHub ↗
(currentCourses: Course[], allCourses: Course[])

Source from the content-addressed store, hash-verified

23export const APPX_COURSE_IDS = [1, 2, 3, 8, 9, 10, 11, 12, 25, 26, 27, 28];
24
25function getExtraCourses(currentCourses: Course[], allCourses: Course[]) {
26 const hasCohort2 = currentCourses
27 .map((x) => x.id.toString())
28 .find((x) => ['1', '2', '3'].includes(x.toString()));
29
30 const hasCohort3 = currentCourses.find((x) =>
31 COHORT_3_PARENT_COURSES.map((x) => x.toString()).includes(x.id.toString()),
32 );
33
34 const hasCohort4 = currentCourses.find((x) => COHORT_4_PARENT_COURSES.map((y) => y.toString()).includes(x.id.toString()));
35
36 let initialCourses: Course[] = [];
37
38 if (hasCohort2) {
39 initialCourses = [...allCourses.filter((x) => x.openToEveryone)];
40 } else if (hasCohort3 || hasCohort4) {
41 initialCourses = [...allCourses.filter((x) => x.id === 7 || x.id === 4)];
42 }
43
44 // We break down parent courses into child courses
45 // for eg, (web dev + devops) breaks down to web dev and devops
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 }
59
60 if (currentCourses.find((x) => x.id === 9)) {
61 hasWebDev = true;
62 hasDevOps = true;
63 }
64
65 if (currentCourses.find((x) => x.id === 10)) {
66 hasWeb3 = true;
67 }
68
69 if (currentCourses.find((x) => x.id === 11)) {
70 hasWebDev = true;
71 }
72
73 if (currentCourses.find((x) => x.id === 12)) {
74 hasDevOps = true;
75 }
76
77 if (hasWebDev) {
78 userCourses.push(allCourses.find((x) => x.id === 14)!);
79 }
80
81 if (hasDevOps) {
82 userCourses.push(allCourses.find((x) => x.id === 15)!);

Callers 1

getPurchasesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected