Skip to content

Commit

Permalink
fix: treat empty string as unknown instead
Browse files Browse the repository at this point in the history
  • Loading branch information
harshkhandeparkar committed Nov 3, 2024
1 parent 1401772 commit 7da0313
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/src/qp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl From<Exam> for String {
match value {
Exam::Midsem => "midsem".into(),
Exam::Endsem => "endsem".into(),
Exam::Unknown => "unknown".into(),
Exam::Unknown => "".into(),
Exam::CT(None) => "ct".into(),
Exam::CT(Some(i)) => format!("ct{}", i),
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Common/PaperEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function PaperEditModal<T extends IQuestionPaperFile | IAdminDashboardQP>(props:
}

if (validateYear(data.year)) similarityDetails['year'] = data.year;
if (validateExam(data.exam) && data.exam !== 'unknown' && data.exam !== 'ct') similarityDetails['exam'] = data.exam;
if (validateExam(data.exam) && data.exam !== '' && data.exam !== 'ct') similarityDetails['exam'] = data.exam;
if (validateSemester(data.semester)) similarityDetails['semester'] = data.semester;

getSimilarPapers(similarityDetails);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Search/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function ResultCard(result: ISearchResult) {
// unknown - N/A
// midsem - MID; endsem - END
// ctx - CT1, CT2, etc.
return exam === 'unknown' ? 'N/A' :
return exam === '' ? 'N/A' :
(exam === 'midsem' || exam === 'endsem') ?
exam.slice(0, 3).toUpperCase() :
exam.toUpperCase();
Expand All @@ -178,7 +178,7 @@ function ResultCard(result: ISearchResult) {
// unknown - Exam Unknown
// midsem - Midsem; endsem - Endsem
// ctx - Class Test 1, Class Test 2, etc.
return exam === 'unknown' ? 'Exam Unknown' :
return exam === '' ? 'Exam Unknown' :
(exam === 'midsem' || exam === 'endsem') ?
exam[0].toUpperCase() + exam.slice(1) :
`Class Test ${exam.slice(2).length > 0 ? exam.slice(2) : '?'}`;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/question_paper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IQuestionPaper {
course_name: string;
year: number;
semester: Semester;
exam: Exam | "ct" | "unknown";
exam: Exam | "ct" | "";
};

export interface ISearchResult extends IQuestionPaper {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/autofillData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const autofillData = async (

const course_code = filenameOrPdfFallback(filenameCourseCode, pdfCourseCode, validateCourseCode, 'Unknown Course');
const year = filenameOrPdfFallback(filenameYear, pdfYear, validateYear, new Date().getFullYear());
const exam = filenameOrPdfFallback(filenameExam, pdfExam, validateExam, 'unknown');
const exam = filenameOrPdfFallback(filenameExam, pdfExam, validateExam, '');
const semester = filenameOrPdfFallback(filenameSemester, pdfSemester, validateSemester, new Date().getMonth() > 7 ? "autumn" : "spring");

const qpDetails: IQuestionPaper = {
Expand Down

0 comments on commit 7da0313

Please sign in to comment.