diff --git a/api/migrate-mysql.js b/api/migrate-mysql.js index b257d887..68fbacb0 100644 --- a/api/migrate-mysql.js +++ b/api/migrate-mysql.js @@ -161,13 +161,18 @@ async function importData() { e.years = element.years; e.enabled = element.enabled; e.enable_sharing = element.enable_sharing; - e.groups = {} + const my_groups = {} groups .filter(g => g.degree_id===element.id) - .map(g => { - e.groups[g.name] = exams_groups + .forEach(g => { + const exam_ids = exams_groups .filter(eg => eg.group_id===g.id) - .map(eg => exams[eg.exam_id]._id)}); + .map(eg => new ObjectId(exams[eg.exam_id]._id)) + my_groups[g.name] = exam_ids + }) + + e.groups = my_groups + if (element.default_group_id) { e.default_group = group_by_id(element.default_group_id).name; } else { diff --git a/frontend/src/modules/engine.tsx b/frontend/src/modules/engine.tsx index e316cb99..c703b054 100644 --- a/frontend/src/modules/engine.tsx +++ b/frontend/src/modules/engine.tsx @@ -341,33 +341,47 @@ export type ProposalGet = { attachments: ProposalAttachmentGet[], } -export type ProposalExamGet = { +export type ProposalExamGet = + ProposalCompulsoryExamGet | + ProposalCompulsoryGroupGet | + ProposalFreeChoiceGet + + +export type ProposalCompulsoryExamGet = { __t: "CompulsoryExam", exam_id: string, exam_name: string, exam_code: string, exam_credits: number, -}|{ +} + +export type PoposalCompulsoryGroupGet = { __t: "CompulsoryGroup", group: string, exam_id: string, exam_name: string, exam_code: string, exam_credits: number, -}|{ +} + +export type ProposalFreeChoiceGroupGet = { __t: "FreeChoiceGroup", group: string, exam_id: string, exam_name: string, exam_code: string, exam_credits: number, -}|{ +} + +export type ProposalFreeChoiceGet = { __t: "FreeChoiceExam", exam_id: string, exam_name: string, exam_code: string, exam_credits: number, -}|{ +} + +export type ProposalExternalExamGet = { __t: "ExternalExam", exam_name: string, exam_credits: number, diff --git a/frontend/src/pages/ProposalPage.tsx b/frontend/src/pages/ProposalPage.tsx index c13d117b..04d37a17 100644 --- a/frontend/src/pages/ProposalPage.tsx +++ b/frontend/src/pages/ProposalPage.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { Dispatch, SetStateAction, useState } from 'react' import { useParams } from "react-router-dom" import {Button} from 'react-bootstrap' import assert from 'assert' @@ -7,7 +7,7 @@ import { useEngine, useGet, useIndexExam, useGetProposal, useIndexDegree, useIndexCurriculum, useGetDegree, useGetCurriculum, useGetExam, - ExamGet, ProposalGet, ProposalExamGet } from '../modules/engine' + ExamGet, ProposalGet, ProposalExamGet, CurriculumExamGet } from '../modules/engine' import LoadingMessage from '../components/LoadingMessage' import Card from '../components/Card' import {formatDate,displayAcademicYears} from '../modules/utils' @@ -138,8 +138,15 @@ function ProposalForm({ proposal }:{ console.log(chosenExams) - - function ExamSelect({ exam, allExams, groups, yearNumber, examNumber, chosenExams, setChosenExams }) { + function ExamSelect({ exam, allExams, groups, yearNumber, examNumber, chosenExams, setChosenExams }:{ + exam: CurriculumExamGet, + allExams: {[key: string]: ExamGet}, + groups: {[key: string]: ExamGet[]}, + yearNumber: number, + examNumber: number, + chosenExams: (ProposalExamGet|null)[][], + setChosenExams: Dispatch>, + }) { if (exam.__t === "CompulsoryExam") { const compulsoryExam = allExams[exam.exam_id] return
  • @@ -156,23 +163,40 @@ function ProposalForm({ proposal }:{
  • } else if (exam.__t === "CompulsoryGroup") { const options = groups[exam.group] + + function isCompulsoryGroupExam(exm: ProposalExamGet|null): asserts exm is ProposalExamGet { + assert(exm !== null && exm.__t === "CompulsoryGroup") + } + + const exm = chosenExams[yearNumber][examNumber] + + assert (!exm || exm.__t === "CompulsoryGroup") + console.log(exm?.exam_id) return
  • - +
  • diff --git a/frontend/src/pages/SinglePage.js b/frontend/src/pages/SinglePage.js index 7ef14380..c794357a 100644 --- a/frontend/src/pages/SinglePage.js +++ b/frontend/src/pages/SinglePage.js @@ -61,7 +61,6 @@ function SinglePageInternal () { }/> }/> }/> - }/> }/> }/> {/* }/> */}