Skip to content

Commit

Permalink
Merge pull request #761 from rage/progress-fix
Browse files Browse the repository at this point in the history
General API - Progress
  • Loading branch information
d471061c committed Apr 30, 2021
2 parents 70295bc + b9ab2cb commit 9576e75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 11 additions & 3 deletions packages/backendv2/src/controllers/general/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import Router from "koa-router"
import { CustomContext, CustomState } from "../../types"
import { checkAccessOrThrow } from "../dashboard/util"
import { UserQuizState, Quiz } from "../../models/"
import Quiz from "../../models/quiz"
import UserCoursePartState from "../../models/user_course_part_state"
import accessControl from "../../middleware/access_control"
import knex from "../../../database/knex"

const general = new Router<CustomState, CustomContext>({
prefix: "/general",
})
.get("/course/:courseId/progress", accessControl(), async ctx => {
const courseId = ctx.params.courseId
const user = ctx.state.user
ctx.body = await UserQuizState.getByUserAndCourse(user.id, courseId)
try {
ctx.body = await knex.transaction(
async trx =>
await UserCoursePartState.getProgress(user.id, courseId, trx),
)
} catch (err) {
throw err
}
})

.get("/course/:courseId/quiz-titles", accessControl(), async ctx => {
Expand Down
12 changes: 5 additions & 7 deletions packages/backendv2/tests/generalApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("general-api", () => {
return [
200,
{
id: 1234,
id: 2345,
administrator: true,
} as UserInfo,
]
Expand Down Expand Up @@ -92,12 +92,10 @@ describe("general-api", () => {
const progress = data[0]
expect(progress).toBeObject()
expect(progress).toContainAllKeys([
"quizId",
"peerReviewsGiven",
"peerReviewsReceived",
"tries",
"status",
"pointsAwarded",
"group",
"progress",
"n_points",
"max_points",
])
})
.end(done)
Expand Down

0 comments on commit 9576e75

Please sign in to comment.