Skip to content

Commit

Permalink
Fix Questions not Saving and Improper AssignmentSet Fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Nephelite committed Oct 24, 2024
1 parent 17f34c5 commit 90da3a5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 35 deletions.
11 changes: 3 additions & 8 deletions backend/controllers/assessmentAssignmentSetController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getAssignmentSetController = async (req: Request, res: Response) =>

try {
const assignmentSet = await getAssignmentSetByAssessmentId(assessmentId);
res.status(200).json(assignmentSet.assignedTeams);
res.status(200).json(assignmentSet.assignedTeams === null ? assignmentSet.assignedUsers : assignmentSet.assignedTeams);
} catch (error) {
if (error instanceof NotFoundError) {
res.status(404).json({ error: error.message });
Expand All @@ -60,15 +60,10 @@ export const getAssignmentSetController = async (req: Request, res: Response) =>
*/
export const updateAssignmentSetController = async (req: Request, res: Response) => {
const { assessmentId } = req.params;
const { assignedTeams } = req.body;

// Validate input
if (!Array.isArray(assignedTeams)) {
return res.status(400).json({ error: 'assignedTeams must be an array' });
}
const { assignedTeams, assignedUsers } = req.body;

try {
const updatedSet = await updateAssignmentSet(assessmentId, assignedTeams);
const updatedSet = await updateAssignmentSet(assessmentId, assignedTeams, assignedUsers);
res.status(200).json(updatedSet);
} catch (error) {
if (error instanceof NotFoundError || error instanceof BadRequestError) {
Expand Down
1 change: 1 addition & 0 deletions backend/services/assessmentAssignmentSetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export const updateAssignmentSet = async (
if (!ta) {
throw new NotFoundError(`TA with ID ${taId} not found`);
}
console.log('adding ta:', ta)
}
}

Expand Down
1 change: 1 addition & 0 deletions backend/services/internalAssessmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ export const addQuestionToAssessment = async (
questionData: Partial<QuestionUnion>,
accountId: string
): Promise<QuestionUnion> => {
console.log(questionData)
const account = await AccountModel.findById(accountId);
if (!account) {
throw new NotFoundError('Account not found');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const AssessmentMakeQuestionCard: React.FC<AssessmentMakeQuestionCardProps> = ({
isLocked,
index,
}) => {
const enableNewQuestionTypesForTesting = true; // Set to false in production
const enableNewQuestionTypesForTesting = false; // Set to false in production
const isQuestionLocked = isLocked || questionData.isLocked || false;

// Determine if this is a new question (temporary _id starting with 'temp-')
Expand Down Expand Up @@ -379,7 +379,7 @@ const AssessmentMakeQuestionCard: React.FC<AssessmentMakeQuestionCardProps> = ({
...questionData,
text: questionText,
type: questionType,
shortResponsePlaceholder,
shortResponsePlaceholder: shortResponsePlaceholder || 'Enter your response here...',
customInstruction: customInstruction || getDefaultInstruction(),
isLocked: questionData.isLocked || false,
isRequired, // Added isRequired
Expand All @@ -390,18 +390,18 @@ const AssessmentMakeQuestionCard: React.FC<AssessmentMakeQuestionCardProps> = ({
...questionData,
text: questionText,
type: questionType,
longResponsePlaceholder: shortResponsePlaceholder,
longResponsePlaceholder: shortResponsePlaceholder || 'Enter your response here...',
customInstruction: customInstruction || getDefaultInstruction(),
isLocked: questionData.isLocked || false,
isRequired, // Added isRequired
isRequired,
} as LongResponseQuestion;
break;
case 'Date':
updatedQuestion = {
...questionData,
text: questionText,
type: questionType,
isRange,
isRange: isRange || false,
datePickerPlaceholder,
minDate: minDate || undefined,
maxDate: maxDate || undefined,
Expand Down Expand Up @@ -1042,16 +1042,21 @@ const AssessmentMakeQuestionCard: React.FC<AssessmentMakeQuestionCardProps> = ({
/>

<Group grow style={{ marginTop: '16px', gap: '16px' }}>
<DatePicker
placeholder="Select min date"
value={minDate}
onChange={(date) => setMinDate(date)}
/>
<DatePicker
placeholder="Select max date"
value={maxDate}
onChange={(date) => setMaxDate(date)}
/>
<Box>
<Text>{'Earliest Valid Date'}</Text>
<DatePicker
value={minDate}
onChange={(date) => setMinDate(date)}
/>
</Box>
<Box>
<Text>{'Latest Valid Date'}</Text>
<DatePicker
placeholder="Select max date"
value={maxDate}
onChange={(date) => setMaxDate(date)}
/>
</Box>
</Group>
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ const InternalAssessmentDetail: React.FC = () => {
const response = await fetch(`/api/internal-assessments/${assessmentId}/assignment-sets`);
if (response.ok) {
assignedTeams = await response.json();
} else {
}

if (!response.ok || assignedTeams === null) {
// Fallback to the old API route if the assignment set is not available
const fallbackResponse = await fetch(`/api/teams/course/${id}`);
if (!fallbackResponse.ok) {
if (!fallbackResponse.ok && response !== null) {
console.error('Error fetching teams from fallback:', fallbackResponse.statusText);
return;
}
Expand Down Expand Up @@ -82,19 +84,25 @@ const InternalAssessmentDetail: React.FC = () => {
const response = await fetch(`/api/internal-assessments/${assessmentId}/assignment-sets`);
if (response.ok) {
assignedUsers = await response.json();
} else {
}

if (!response.ok || assignedUsers === null) {
// Fetch enrolled students as AssignedUsers
const studentsResponse = await fetch(`/api/courses/${id}/students`);
if (!studentsResponse.ok) {
console.error('Error fetching students:', studentsResponse.statusText);
const fallbackResponse = await fetch(`/api/teams/course/${id}`);
if (!fallbackResponse.ok) {
console.error('Error fetching teams from fallback:', fallbackResponse.statusText);
return;
}
const students: User[] = await studentsResponse.json();

assignedUsers = students.map((student) => ({
user: student,
tas: [], // Initialize with empty tas
} as AssignedUser));
const teams: Team[] = await fallbackResponse.json();
console.log(teams)

// Construct AssignedUser from old Team structure
assignedUsers = teams.flatMap((team) => team.members.map((member) => {
return {
user: member,
tas: team.TA ? [team.TA] : [],
} as AssignedUser
}));
}

const userMap: { [key: string]: string } = {};
Expand Down

0 comments on commit 90da3a5

Please sign in to comment.