forked from rage/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.js
More file actions
57 lines (54 loc) · 1.61 KB
/
progress.js
File metadata and controls
57 lines (54 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { fetchProgrammingProgress, getCachedUserDetails } from "./moocfi"
import { zip } from "../util/arrays"
import { fetchQuizProgress } from "./quiznator"
import { fetchQuizzesProgress } from "./quizzes"
const introductionCourseGroups = [
"osa01",
"osa02",
"osa03",
"osa04",
"osa05",
"osa06",
"osa07",
]
export async function fetchProgress() {
// await fetchQuizzesProgress()
const serviceIdentifiers = ["Programming exercises", "Quizzes"]
const progressesCollection = await Promise.all([
fetchProgrammingProgress(),
fetchQuizzesProgress(),
])
const userDetails = await getCachedUserDetails()
const currentCourseVariant = userDetails?.extra_fields?.course_variant
const progressByGroup = {}
zip(serviceIdentifiers, progressesCollection).forEach(
([identifier, progresses]) => {
console.log(JSON.stringify(progresses))
progresses.forEach((progressEntry) => {
const group = progressEntry.group.replace("osa", "part")
if (!progressByGroup[group]) {
progressByGroup[group] = {}
}
progressByGroup[group][identifier] = progressEntry
})
},
)
const toBeDeleted = []
Object.entries(progressByGroup).forEach(([group, serviceEntries]) => {
if (
!Object.keys(serviceEntries).find((o) => o === "Programming exercises")
) {
toBeDeleted.push(group)
}
})
if (
currentCourseVariant === "ohja-dl" ||
currentCourseVariant === "ohja-nodl"
) {
introductionCourseGroups.forEach((group) => toBeDeleted.push(group))
}
toBeDeleted.forEach((o) => {
delete progressByGroup[o]
})
return progressByGroup
}