Skip to content

Commit

Permalink
Merge pull request #156 from sparcs-kaist/155-fix-adjust-to-new-code
Browse files Browse the repository at this point in the history
fix: course search adjust to new code
  • Loading branch information
Gerbera3090 authored Jan 5, 2025
2 parents cb6ed64 + b6e56e3 commit a1a4c31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/common/utils/search.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,19 @@ export async function validateYearAndSemester(
(2009 < year && year < 2018 && semester && [1, 3].includes(semester))
);
}

export function formatNewLectureCodeWithDot(keyword: string): string {
// new_code의 .을 수용할 수 있게 과목코드를 바꿔주는 함수

// 정규식: [알파벳]+[숫자]+ 형식 매칭
const regex = /^([a-zA-Z]+)(\d+)$/;

// 키워드가 정규식에 매칭되면 변환, 매칭되지 않으면 원래 값을 반환
const match = keyword.match(regex);
if (match) {
const [, letters, numbers] = match; // 알파벳 그룹과 숫자 그룹 추출
return `${letters}.${numbers}`; // 알파벳과 숫자 사이에 '.' 삽입
}

return keyword; // 변환 불가능한 경우 원래 키워드 반환
}
8 changes: 8 additions & 0 deletions src/prisma/repositories/course.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ICourse } from 'src/common/interfaces';
import {
applyOffset,
applyOrder,
formatNewLectureCodeWithDot,
orderFilter,
} from 'src/common/utils/search.utils';
import { PrismaService } from '../prisma.service';
Expand Down Expand Up @@ -312,11 +313,18 @@ export class CourseRepository {
contains: keyword_space_removed,
},
};

const new_code_filter = {
new_code: {
contains: formatNewLectureCodeWithDot(keyword_space_removed),
},
};
return {
OR: [
title_filter,
en_title_filter,
old_code_filter,
new_code_filter,
department_name_filter,
department_name_en_filter,
professors_professor_name_filter,
Expand Down

0 comments on commit a1a4c31

Please sign in to comment.