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
53 lines (50 loc) · 1.56 KB
/
Copy pathprogress.js
File metadata and controls
53 lines (50 loc) · 1.56 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
import { fetchProgrammingProgress, getCachedUserDetails } from "./moocfi"
import { fetchCrowdsorcererProgress } from "./crowdsorcerer"
import { zip } from "../util/arrays"
import { fetchQuiznatorProgress } from "./quiznator"
const introductionCourseGroups = [
"osa01",
"osa02",
"osa03",
"osa04",
"osa05",
"osa06",
"osa07",
]
export async function fetchProgress() {
const serviceIdentifiers = ["Ohjelmointitehtävät", "Kyselyt", "Crowdsorcerer"]
const progressesCollection = await Promise.all([
fetchProgrammingProgress(),
fetchQuiznatorProgress(),
fetchCrowdsorcererProgress(),
])
const userDetails = await getCachedUserDetails()
const currentCourseVariant = userDetails?.extra_fields?.course_variant
const progressByGroup = {}
zip(serviceIdentifiers, progressesCollection).forEach(
([identifier, progresses]) => {
progresses.forEach(progressEntry => {
if (!progressByGroup[progressEntry.group]) {
progressByGroup[progressEntry.group] = {}
}
progressByGroup[progressEntry.group][identifier] = progressEntry
})
},
)
const toBeDeleted = []
Object.entries(progressByGroup).forEach(([group, serviceEntries]) => {
if (!Object.keys(serviceEntries).find(o => o === "Ohjelmointitehtävät")) {
toBeDeleted.push(group)
}
})
if (
currentCourseVariant === "ohja-dl" ||
currentCourseVariant === "ohja-nodl"
) {
introductionCourseGroups.forEach(group => toBeDeleted.push(group))
}
toBeDeleted.forEach(o => {
delete progressByGroup[o]
})
return progressByGroup
}