Skip to content

Commit

Permalink
fix: change number to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
yougyung committed Sep 26, 2024
1 parent 28ceccf commit c132ad4
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,34 @@ import {
import { ResultCategoryKey } from '../result-category-detail-content/result-category-detail-content.stories';
import { RESULT_CATEGORY } from '@/app/utils/key/result-category.key';

const CHAPEL_TOTAL_CREDIT = 2.0;
const CHAPEL_TOTAL_COUNT = 4;
const CHAPEL_CREDIT = CHAPEL_TOTAL_CREDIT / CHAPEL_TOTAL_COUNT;

const CHAPEL_LECTURE_INFO: LectureInfoResponse = {
id: 0,
lectureCode: 'KMA02101',
name: '채플',
credit: 0.5,
credit: CHAPEL_CREDIT,
};

function addChapelToCommonCulture(
info: ResultCategoryDetailLecturesResponse[],
chapel?: CreditResponse,
): ResultCategoryDetailLecturesResponse[] {
if (!chapel) return info;
const takenChapel = chapel.takenCredit / 0.5;
const haveToChapel = Math.max(0, 4 - takenChapel);
const takenChapelCount = chapel.takenCredit / CHAPEL_CREDIT;
const haveToChapelCount = Math.max(0, CHAPEL_TOTAL_COUNT - takenChapelCount);

return [
...info,
{
categoryName: '채플',
completed: takenChapel * 0.5 >= 2.0,
totalCredit: 2.0,
takenCredit: takenChapel * 0.5,
haveToLectures: Array(haveToChapel).fill(CHAPEL_LECTURE_INFO),
takenLectures: Array(takenChapel).fill(CHAPEL_LECTURE_INFO),
completed: takenChapelCount >= CHAPEL_TOTAL_COUNT,
totalCredit: CHAPEL_TOTAL_CREDIT,
takenCredit: chapel.takenCredit,
haveToLectures: Array(haveToChapelCount).fill(CHAPEL_LECTURE_INFO),
takenLectures: Array(takenChapelCount).fill(CHAPEL_LECTURE_INFO),
},
];
}
Expand All @@ -41,7 +45,7 @@ export default function ResultCategoryDetailInfo({ category }: { category: Resul
const { data: categoryInfo } = useFetchResultCategoryDetailInfo(category);
const { data: categories } = useFetchCredits();

const chapel = categories.find((category) => category.category === 'CHAPEL');
const chapel = categories.find(({ category }) => category === 'CHAPEL');
const isCommonCulture = category === RESULT_CATEGORY.COMMON_CULTURE;
const detailCategory = isCommonCulture
? addChapelToCommonCulture(categoryInfo.detailCategory, chapel)
Expand Down

0 comments on commit c132ad4

Please sign in to comment.