Skip to content

Commit

Permalink
feat(excel): excel데이터 어뎁터 패턴 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
racgoo committed Aug 25, 2024
1 parent 4eb494a commit 22f50f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/admin/src/pages/winner/WinnerResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Button } from 'src/components/ui/button.tsx';
import useEvent from 'src/hooks/useEvent.tsx';
import { QuizWinner, RacingWinner } from 'src/services/api/types/apiType.ts';
import { useAlert } from 'src/store/provider/AlertProvider.tsx';
import { transformQuizWinnersToExcel, transformRaceWinnersToExcel } from 'src/utils/adaptor.ts';
import excelDownload from 'src/utils/xlsx.ts';

const TabName = {
Expand Down Expand Up @@ -86,13 +87,13 @@ function WinnerResult() {
if (quizWinner === undefined) {
return openAlert('데이터가 없습니다.', 'alert');
}
excelDownload(quizWinner, '퀴즈 위너');
excelDownload(transformQuizWinnersToExcel(quizWinner), '퀴즈 위너');
}
if (tabName === TabName.RACE) {
if (racingWinners === undefined) {
return openAlert('데이터가 없습니다.', 'alert');
}
excelDownload(racingWinners, '레이싱 위너');
excelDownload(transformRaceWinnersToExcel(racingWinners), '레이싱 위너');
}
};

Expand Down
18 changes: 18 additions & 0 deletions packages/admin/src/utils/adaptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { QuizWinner, RacingWinner } from 'src/services/api/types/apiType.ts';

export function transformQuizWinnersToExcel(quizWinners: QuizWinner[]): object[] {
return quizWinners.map((winner) => ({
이름: winner.name,
이메일: winner.phoneNumber,
당첨일: winner.postDate,
}));
}
export function transformRaceWinnersToExcel(raceWinners: RacingWinner[]): object[] {
return raceWinners.map((winner) => ({
: winner.rank,
이름: winner.name,
이메일: winner.phoneNumber,
공유링크: winner.clickNumber,
: winner.team,
}));
}

0 comments on commit 22f50f2

Please sign in to comment.