Skip to content

Commit

Permalink
chore: unify and simplify types structure for element options (#4475)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjschlapbach authored Jan 24, 2025
1 parent 1367343 commit 7f474dd
Show file tree
Hide file tree
Showing 25 changed files with 758 additions and 790 deletions.
2 changes: 1 addition & 1 deletion apps/func-response-processor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DEFAULT_POINTS = 10 // points a participant gets for participating in a po
const DEFAULT_CORRECT_POINTS = 5 // points a participant gets for answering correctly (independent of time)

// TODO: what if the participant is not part of the course? when starting a session, prepopulate the leaderboard with all participations? what if a participant joins the course during a session? filter out all 0 point participants before rendering the LB
// TODO: ensure that the response meets the restrictions specified in the question options
// TODO: ensure that the response meets the restrictions specified in the element options

Sentry.init()

Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/lib/validateAndProcessElementOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import validateNumericalOptions from './validateNumericalOptions.js'
import validateSCOptions from './validateSCOptions.js'
import validateSelectionOptions from './validateSelectionOptions.js'

export interface QuestionOptionsArgs {
export interface ElementOptionsArgs {
unit?: string | null // NR only
accuracy?: number | null // NR only
placeholder?: string | null // NR/FT only
Expand Down Expand Up @@ -40,7 +40,7 @@ export interface QuestionOptionsArgs {

function validateAndProcessElementOptions(
elementType: DB.ElementType,
options?: QuestionOptionsArgs | null
options?: ElementOptionsArgs | null
) {
switch (elementType) {
case DB.ElementType.SC:
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/lib/validateElementInputs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as DB from '@klicker-uzh/prisma'
import { QuestionOptionsArgs } from './validateAndProcessElementOptions.js'
import { ElementOptionsArgs } from './validateAndProcessElementOptions.js'

export interface ManipulateQuestionArgs {
id?: number | null
Expand All @@ -8,7 +8,7 @@ export interface ManipulateQuestionArgs {
name?: string | null
content?: string | null
explanation?: string | null
options?: QuestionOptionsArgs | null
options?: ElementOptionsArgs | null
pointsMultiplier?: number | null
tags?: string[] | null
}
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/lib/validateFreeTextOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QuestionOptionsArgs } from './validateAndProcessElementOptions.js'
import { ElementOptionsArgs } from './validateAndProcessElementOptions.js'

function validateFreeTextOptions(options?: QuestionOptionsArgs | null) {
function validateFreeTextOptions(options?: ElementOptionsArgs | null) {
// options and hasSampleSolution need to be defined
if (
!options ||
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/lib/validateKPRIMOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QuestionOptionsArgs } from './validateAndProcessElementOptions.js'
import { ElementOptionsArgs } from './validateAndProcessElementOptions.js'
import validateSharedChoicesFields from './validateSharedChoicesFields.js'

function validateKPRIMOptions(options?: QuestionOptionsArgs | null) {
function validateKPRIMOptions(options?: ElementOptionsArgs | null) {
let valid = validateSharedChoicesFields(options)
if (!valid) return false

Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/lib/validateMCOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QuestionOptionsArgs } from './validateAndProcessElementOptions.js'
import { ElementOptionsArgs } from './validateAndProcessElementOptions.js'
import validateSharedChoicesFields from './validateSharedChoicesFields.js'

function validateMCOptions(options?: QuestionOptionsArgs | null) {
function validateMCOptions(options?: ElementOptionsArgs | null) {
let valid = validateSharedChoicesFields(options)
if (!valid) return false

Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/lib/validateNumericalOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QuestionOptionsArgs } from './validateAndProcessElementOptions.js'
import { ElementOptionsArgs } from './validateAndProcessElementOptions.js'

function validateNumericalOptions(options?: QuestionOptionsArgs | null) {
function validateNumericalOptions(options?: ElementOptionsArgs | null) {
// options and hasSampleSolution need to be defined
if (
!options ||
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/lib/validateSCOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QuestionOptionsArgs } from './validateAndProcessElementOptions.js'
import { ElementOptionsArgs } from './validateAndProcessElementOptions.js'
import validateSharedChoicesFields from './validateSharedChoicesFields.js'

function validateSCOptions(options?: QuestionOptionsArgs | null) {
function validateSCOptions(options?: ElementOptionsArgs | null) {
let valid = validateSharedChoicesFields(options)
if (!valid) return false

Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/lib/validateSelectionOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QuestionOptionsArgs } from './validateAndProcessElementOptions.js'
import { ElementOptionsArgs } from './validateAndProcessElementOptions.js'

function validateSelectionOptions(options?: QuestionOptionsArgs | null) {
function validateSelectionOptions(options?: ElementOptionsArgs | null) {
// options and hasSampleSolution need to be defined
if (
!options ||
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/lib/validateSharedChoicesFields.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DisplayMode } from '@klicker-uzh/types'
import { QuestionOptionsArgs } from './validateAndProcessElementOptions.js'
import { ElementOptionsArgs } from './validateAndProcessElementOptions.js'

function validateSharedChoicesFields(options?: QuestionOptionsArgs | null) {
function validateSharedChoicesFields(options?: ElementOptionsArgs | null) {
// options and choices therein need to be defined
if (!options || !options.choices) {
console.error('Options are required on choices questions')
Expand Down
Loading

0 comments on commit 7f474dd

Please sign in to comment.