Skip to content

Commit

Permalink
Merge branch 'master' into feat-add-user-organization-join-confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
mipyykko committed Oct 20, 2022
2 parents 612fe8b + a8f67c5 commit 61752fb
Show file tree
Hide file tree
Showing 56 changed files with 755 additions and 493 deletions.
2 changes: 1 addition & 1 deletion backend/bin/fetchAvoinLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const getInfoWithCourseCode = async (
const res = await axios.get(url, {
headers: { Authorized: "Basic " + AVOIN_TOKEN },
})
return await res.data
return res.data
}

interface AvoinLinkData {
Expand Down
2 changes: 1 addition & 1 deletion backend/bin/importOrganizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const getUserFromTmc = async (user_id: number) => {
username: details.username,
}

return await prisma.user.upsert({
return prisma.user.upsert({
where: { upstream_id: details.id },
create: prismaDetails,
update: convertUpdate(prismaDetails),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const tmc = fakeTMCSpecific({
9999: [404, { errors: "asdf" }],
})

function expectIsDefined<T>(value: T | null | undefined): asserts value is T {
expect(value).toBeDefined()
}

describe("userPoints/saveToDatabase", () => {
const kafkaContext = {} as KafkaContext

Expand Down Expand Up @@ -193,6 +197,12 @@ describe("userPoints/saveToDatabase", () => {
},
})

expectIsDefined(existing)
expect(
existing.exercise_completion_required_actions.map((ra) => ra.value)
.length,
).toEqual(0)

const ret = await saveToDatabase(kafkaContext, {
...message,
timestamp: "2000-03-01T10:00:00.00+02:00",
Expand All @@ -211,8 +221,10 @@ describe("userPoints/saveToDatabase", () => {
exercise_completion_required_actions: true,
},
})

expect(updated?.updated_at! > existing?.updated_at!).toBeTruthy()
expectIsDefined(updated)
expect(updated.updated_at?.valueOf() ?? -Infinity).toBeGreaterThan(
existing.updated_at?.valueOf() ?? -Infinity,
)
expect(
updated?.exercise_completion_required_actions
.map((ra) => ra.value)
Expand Down
8 changes: 4 additions & 4 deletions backend/bin/lib/await-semaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export class Semaphore {
private sched() {
if (this.count > 0 && this.tasks.length > 0) {
this.count--
let next = this.tasks.shift()
const next = this.tasks.shift()
if (next === undefined) {
throw "Unexpected undefined value in tasks list"
throw new Error("Unexpected undefined value in tasks list")
}

next()
Expand All @@ -20,8 +20,8 @@ export class Semaphore {

public acquire() {
return new Promise<() => void>((res, _) => {
var task = () => {
var released = false
const task = () => {
let released = false
res(() => {
if (!released) {
released = true
Expand Down
4 changes: 2 additions & 2 deletions backend/bin/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ const seed = async () => {
: undefined,
}

return await prisma.studyModule.create({
return prisma.studyModule.create({
data: _module,
})
}),
)

return await Promise.all(
return Promise.all(
Courses.map(async (course) => {
const _course = {
...course,
Expand Down
8 changes: 4 additions & 4 deletions backend/bin/seedPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const addServices = async () => {
const addUserCourseProgressess = async (courseId: string) => {
const usersInDb = await prisma.user.findMany({ take: 100 })

return await Promise.all(
return Promise.all(
usersInDb.map(async (user) => {
const progress = [
{
Expand Down Expand Up @@ -126,14 +126,14 @@ const addUserCourseProgressess = async (courseId: string) => {
max_points: progress.reduce((acc, curr) => acc + curr.max_points, 0),
}

return await prisma.userCourseProgress.create({ data: ucp })
return prisma.userCourseProgress.create({ data: ucp })
}),
)
}

const addUserCourseSettingses = async (courseId: string) => {
const UsersInDb = await prisma.user.findMany({ take: 100 })
return await Promise.all(
return Promise.all(
UsersInDb.map(async (user) => {
const ucs: Prisma.UserCourseSettingCreateInput = {
user: {
Expand All @@ -153,7 +153,7 @@ const addUserCourseSettingses = async (courseId: string) => {
course_variant: null,
other: null,
}
return await prisma.userCourseSetting.create({ data: ucs })
return prisma.userCourseSetting.create({ data: ucs })
}),
)
}
Expand Down
47 changes: 24 additions & 23 deletions backend/graphql/ABEnrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,31 @@ export const ABEnrollmentMutations = extendType({
},
})
},
}),
t.field("updateAbEnrollment", {
type: "AbEnrollment",
args: {
abEnrollment: nonNull(
arg({
type: "AbEnrollmentCreateOrUpsertInput",
}),
),
},
authorize: isAdmin,
resolve: async (_, { abEnrollment }, ctx: Context) => {
const { user_id, ab_study_id } = abEnrollment
})

return ctx.prisma.abEnrollment.update({
where: {
user_id_ab_study_id: {
user_id,
ab_study_id,
},
t.field("updateAbEnrollment", {
type: "AbEnrollment",
args: {
abEnrollment: nonNull(
arg({
type: "AbEnrollmentCreateOrUpsertInput",
}),
),
},
authorize: isAdmin,
resolve: async (_, { abEnrollment }, ctx: Context) => {
const { user_id, ab_study_id } = abEnrollment

return ctx.prisma.abEnrollment.update({
where: {
user_id_ab_study_id: {
user_id,
ab_study_id,
},
data: abEnrollment,
})
},
})
},
data: abEnrollment,
})
},
})
},
})
39 changes: 20 additions & 19 deletions backend/graphql/ABStudy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,26 @@ export const ABStudyMutations = extendType({
data: abStudy,
})
},
}),
t.field("updateAbStudy", {
type: "AbStudy",
args: {
abStudy: nonNull(
arg({
type: "AbStudyUpsertInput",
}),
),
},
authorize: isAdmin,
resolve: async (_, { abStudy }, ctx: Context) => {
const { id } = abStudy
})

return ctx.prisma.abStudy.update({
where: { id },
data: abStudy,
})
},
})
t.field("updateAbStudy", {
type: "AbStudy",
args: {
abStudy: nonNull(
arg({
type: "AbStudyUpsertInput",
}),
),
},
authorize: isAdmin,
resolve: async (_, { abStudy }, ctx: Context) => {
const { id } = abStudy

return ctx.prisma.abStudy.update({
where: { id },
data: abStudy,
})
},
})
},
})
6 changes: 3 additions & 3 deletions backend/graphql/Completion/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const Completion = objectType({
},
})

t.field("registered", {
t.nonNull.field("registered", {
type: "Boolean",
resolve: async (parent, _, ctx) => {
const registered = await ctx.prisma.completion
Expand All @@ -117,7 +117,7 @@ export const Completion = objectType({
},
})

t.field("project_completion", {
t.nonNull.field("project_completion", {
type: "Boolean",
resolve: async (parent, _, ctx) => {
if (!parent.course_id) {
Expand Down Expand Up @@ -149,7 +149,7 @@ export const Completion = objectType({
},
})

t.field("certificate_availability", {
t.nullable.field("certificate_availability", {
type: "CertificateAvailability",
resolve: async ({ course_id, user_upstream_id }, _, ctx) => {
if (!course_id) {
Expand Down
2 changes: 1 addition & 1 deletion backend/graphql/Completion/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const CompletionMutations = extendType({
},
})

t.list.field("addManualCompletion", {
t.list.nonNull.field("addManualCompletion", {
type: "Completion",
args: {
completions: list(arg({ type: "ManualCompletionArg" })),
Expand Down
2 changes: 1 addition & 1 deletion backend/graphql/Completion/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { buildUserSearch } from "../common"
export const CompletionQueries = extendType({
type: "Query",
definition(t) {
t.list.field("completions", {
t.list.nonNull.field("completions", {
type: "Completion",
args: {
course: nonNull(stringArg()),
Expand Down
8 changes: 4 additions & 4 deletions backend/graphql/CompletionRegistered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const CompletionRegistered = objectType({
export const CompletionRegisteredQueries = extendType({
type: "Query",
definition(t) {
t.list.field("registeredCompletions", {
t.list.nonNull.field("registeredCompletions", {
type: "CompletionRegistered",
args: {
course: stringArg({ description: "course slug or course alias" }),
Expand Down Expand Up @@ -93,7 +93,7 @@ export const CompletionRegisteredQueries = extendType({
export const CompletionRegisteredMutations = extendType({
type: "Mutation",
definition(t) {
t.field("registerCompletion", {
t.nonNull.field("registerCompletion", {
type: "String",
args: {
completions: nonNull(list(nonNull(arg({ type: "CompletionArg" })))),
Expand All @@ -102,8 +102,8 @@ export const CompletionRegisteredMutations = extendType({
resolve: async (_, args, ctx: Context) => {
const queue = chunk(args.completions, 500)

for (let i = 0; i < queue.length; i++) {
const promises = buildPromises(queue[i], ctx)
for (const element of queue) {
const promises = buildPromises(element, ctx)
await Promise.all(promises)
}
return "success"
Expand Down
24 changes: 12 additions & 12 deletions backend/graphql/Course/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ export const CourseCreateArg = inputObjectType({
t.string("support_email")
t.nonNull.datetime("start_date")
t.datetime("end_date")
t.list.field("study_modules", {
t.list.nonNull.field("study_modules", {
type: "StudyModuleWhereUniqueInput",
})
t.list.nullable.field("course_translations", {
t.list.nonNull.field("course_translations", {
type: "CourseTranslationCreateInput",
})
t.list.nullable.field("open_university_registration_links", {
t.list.nonNull.field("open_university_registration_links", {
type: "OpenUniversityRegistrationLinkCreateInput",
})
t.list.nullable.field("course_variants", {
t.list.nonNull.field("course_variants", {
type: "CourseVariantCreateInput",
})
t.list.nullable.field("course_aliases", {
t.list.nonNull.field("course_aliases", {
type: "CourseAliasCreateInput",
})
t.int("order")
Expand All @@ -43,7 +43,7 @@ export const CourseCreateArg = inputObjectType({
t.nullable.id("inherit_settings_from")
t.nullable.id("completions_handled_by")
t.nullable.boolean("has_certificate")
t.list.nullable.field("user_course_settings_visibilities", {
t.list.nonNull.field("user_course_settings_visibilities", {
type: "UserCourseSettingsVisibilityCreateInput",
})
t.nullable.boolean("upcoming_active_link")
Expand Down Expand Up @@ -76,19 +76,19 @@ export const CourseUpsertArg = inputObjectType({
t.string("support_email")
t.nonNull.datetime("start_date")
t.datetime("end_date")
t.list.field("study_modules", {
t.list.nonNull.field("study_modules", {
type: "StudyModuleWhereUniqueInput",
})
t.list.nullable.field("course_translations", {
t.list.nonNull.field("course_translations", {
type: "CourseTranslationUpsertInput",
})
t.list.nullable.field("open_university_registration_links", {
t.list.nonNull.field("open_university_registration_links", {
type: "OpenUniversityRegistrationLinkUpsertInput",
})
t.list.nullable.field("course_variants", {
t.list.nonNull.field("course_variants", {
type: "CourseVariantUpsertInput",
})
t.list.nullable.field("course_aliases", {
t.list.nonNull.field("course_aliases", {
type: "CourseAliasUpsertInput",
})
t.int("order")
Expand All @@ -100,7 +100,7 @@ export const CourseUpsertArg = inputObjectType({
t.nullable.id("inherit_settings_from")
t.nullable.id("completions_handled_by")
t.nullable.boolean("has_certificate")
t.list.nullable.field("user_course_settings_visibilities", {
t.list.nonNull.field("user_course_settings_visibilities", {
type: "UserCourseSettingsVisibilityUpsertInput",
})
t.nullable.boolean("upcoming_active_link")
Expand Down
4 changes: 2 additions & 2 deletions backend/graphql/Course/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const Course = objectType({
t.string("instructions")
t.string("link")

t.list.field("completions", {
t.list.nonNull.field("completions", {
type: "Completion",
args: {
user_id: nullable(stringArg()),
Expand Down Expand Up @@ -103,7 +103,7 @@ export const Course = objectType({
},
})

t.list.field("exercises", {
t.list.nonNull.field("exercises", {
type: "Exercise",
args: {
includeDeleted: booleanArg({ default: false }),
Expand Down
Loading

0 comments on commit 61752fb

Please sign in to comment.