Skip to content

Commit

Permalink
fix: 응답값을 파싱하는 함수 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
geongyu09 committed Sep 19, 2024
1 parent 5ca3c6b commit 37ab3bd
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
10 changes: 6 additions & 4 deletions frontend/components/applicant/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import Board from "@/components/common/board/Board";
import { getApplicantByPageWithGeneration } from "@/src/apis/applicant";
import ApplicantDetailRight from "./DetailRight.component";
import ApplicantDetailLeft from "./DetailLeft.component";
import { useState } from "react";
import { ApplicantReq } from "@/src/apis/application";
import { applicantDataFinder } from "@/src/functions/finder";
Expand All @@ -12,6 +11,8 @@ import { useSearchParams } from "next/navigation";
import { ORDER_MENU } from "@/src/constants";
import { useSearchQuery } from "@/src/hooks/useSearchQuery";
import { type ApplicantPassState } from "../../src/apis/kanban";
import ApplicantDetailLeft from "./_applicant/ApplicantDetailLeft";
import { findApplicantState } from "@/src/utils/applicant";

interface ApplicantBoardProps {
generation: string;
Expand Down Expand Up @@ -74,9 +75,10 @@ const ApplicantBoard = ({ generation }: ApplicantBoardProps) => {
Number(applicantDataFinder(value, "uploadDate"))
).toLocaleString("ko-KR", { dateStyle: "short" }),
],
passState: `${
applicantDataFinder(value, "passState").passState
}` as ApplicantPassState,
passState: `${applicantDataFinder(
value,
"passState"
)}` as ApplicantPassState,
}));

return (
Expand Down
69 changes: 62 additions & 7 deletions frontend/src/apis/applicant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,46 @@ interface AllApplicantReq {
[string: string]: string;
}

interface ApplicantByPageReqAnswer {
field: string;
field1: string;
field2: string;
name: string;
contacted: string;
classOf: string;
registered: string;
grade: string;
semester: string;
major: string;
doubleMajor: string;
minor: string;
activity: string;
reason: string;
future: string;
experience: string;
experienceTextarea: string;
restoration: string;
deep: string;
collaboration: string;
studyPlan: string;
portfolio: string;
fileUrl: string;
email: string;
check: string;
personalInformationAgree: string;
personalInformationAgreeForPortfolio: string;
generation: string;
uploadDate: string;
channel: string;
timeline: number[];
id: string;
year: number;
created_at: string;
passState: {
passState: ApplicantPassState;
};
}

export const getApplicantByIdWithField = async (
id: string,
fields?: string[]
Expand All @@ -36,9 +76,29 @@ export interface PageInfo {
boardLimit: number;
}

function formatApplicantsDataToApplicantReq(
applicants: ApplicantByPageReqAnswer[]
) {
return applicants.map(
(applicant) =>
Object.keys(applicant).map((key) => {
if (key === "passState") {
return {
name: "passState",
answer: applicant.passState.passState,
};
}
return {
name: key,
answer: applicant[key as keyof ApplicantByPageReqAnswer],
};
}) as ApplicantReq[]
);
}

interface ApplicantByPageReq {
pageInfo: PageInfo;
answers: AllApplicantReq[];
answers: ApplicantByPageReqAnswer[];
}

export const getApplicantByPageWithGeneration = async (
Expand All @@ -54,12 +114,7 @@ export const getApplicantByPageWithGeneration = async (

return {
maxPage: pageInfo.endPage,
applicants: answers.map((applicant) =>
Object.keys(applicant).map((key) => ({
name: key,
answer: applicant[key],
}))
),
applicants: formatApplicantsDataToApplicantReq(answers),
};
};

Expand Down

0 comments on commit 37ab3bd

Please sign in to comment.