From c9c232afcc97b1ec2157fcad880380ac93cccd1a Mon Sep 17 00:00:00 2001 From: "nageuna922@gmail.com" Date: Tue, 10 Dec 2024 13:03:37 +0900 Subject: [PATCH] fix: type --- cspell.json | 1 + .../(routes)/document/[id]/(main)/page.tsx | 2 +- src/app/(routes)/main/page.tsx | 4 +- src/features/quiz/screen/quiz-view/index.tsx | 2 +- src/features/quiz/utils/index.ts | 2 +- src/requests/collection/client.ts | 1 + src/requests/collection/server.ts | 1 + src/requests/document/client.tsx | 3 +- src/requests/document/server.ts | 18 +++- src/requests/quiz/client.tsx | 2 +- src/requests/quiz/hooks.ts | 2 +- src/requests/quiz/server.tsx | 2 +- src/shared/configs/endpoint.ts | 2 +- src/shared/lib/tanstack-query/query-keys.ts | 2 +- src/types/collection.d.ts | 2 + src/types/document.d.ts | 101 ++---------------- src/types/quiz.d.ts | 57 +++++----- 17 files changed, 70 insertions(+), 134 deletions(-) diff --git a/cspell.json b/cspell.json index 5f0dbe32..4a7bdd34 100644 --- a/cspell.json +++ b/cspell.json @@ -23,6 +23,7 @@ "remirror", "svgs", "swipeable", + "taglib", "Tanstack", "Uncapitalize", "vaul", diff --git a/src/app/(routes)/document/[id]/(main)/page.tsx b/src/app/(routes)/document/[id]/(main)/page.tsx index 32306f71..934e8b15 100644 --- a/src/app/(routes)/document/[id]/(main)/page.tsx +++ b/src/app/(routes)/document/[id]/(main)/page.tsx @@ -3,7 +3,7 @@ import DocumentFloatingButton from '@/features/document/components/document-floa import { QuizListProvider } from '@/features/document/contexts/quiz-list-context' import DocumentContent from '@/features/document/screens/document-content' import Quiz from '@/features/document/screens/quiz' -import { fetchDocumentDetail } from '@/requests/document/client' +import { fetchDocumentDetail } from '@/requests/document/server' interface Props { params: { diff --git a/src/app/(routes)/main/page.tsx b/src/app/(routes)/main/page.tsx index 6a798ec9..a1538b09 100644 --- a/src/app/(routes)/main/page.tsx +++ b/src/app/(routes)/main/page.tsx @@ -10,11 +10,11 @@ import InterestedCategoryCollections from '@/features/collection/components/inte import RandomQuizLottie from '@/features/quiz/components/random-quiz-lottie' import BombQuizLottie from '@/features/quiz/components/bomb-quiz-lottie' import { fetchTodayQuizSetId } from '@/requests/quiz/server' -import { fetchDocumentsServer } from '@/requests/document/server' +import { fetchDocuments } from '@/requests/document/server' const Home = async () => { const { quizSetId, createdAt, type } = await fetchTodayQuizSetId() - const { documents } = await fetchDocumentsServer() + const { documents } = await fetchDocuments() const isEmpty = !documents || documents.length === 0 const todayQuizState = isEmpty ? 'EMPTY' : type === 'READY' ? 'ARRIVED' : 'NOT_ARRIVED' diff --git a/src/features/quiz/screen/quiz-view/index.tsx b/src/features/quiz/screen/quiz-view/index.tsx index c4ffda8b..2dc0e1ad 100644 --- a/src/features/quiz/screen/quiz-view/index.tsx +++ b/src/features/quiz/screen/quiz-view/index.tsx @@ -116,7 +116,7 @@ const QuizView = ({ quizzes, isFirst }: Props) => { option === currentQuiz.answer)! : currentQuiz.answer === 'correct' ? 'O' diff --git a/src/features/quiz/utils/index.ts b/src/features/quiz/utils/index.ts index 2d68ef03..95cc79ff 100644 --- a/src/features/quiz/utils/index.ts +++ b/src/features/quiz/utils/index.ts @@ -34,7 +34,7 @@ export const getAnswerText = (answer: string) => { } export const getQuizSetTypeEnum = (quizSetType: 'today' | 'document' | 'collection' | 'create') => { - let enumQuizType: Quiz.SetType + let enumQuizType: Quiz.Set.Type switch (quizSetType) { case 'today': diff --git a/src/requests/collection/client.ts b/src/requests/collection/client.ts index f0b3baaf..cde8c45e 100644 --- a/src/requests/collection/client.ts +++ b/src/requests/collection/client.ts @@ -25,6 +25,7 @@ export const getMyCollections = async () => { } } +/** client에서만 사용 */ export const getBookmarkedCollections = async () => { try { const { data } = await http.get( diff --git a/src/requests/collection/server.ts b/src/requests/collection/server.ts index fdd1a545..2ededa8f 100644 --- a/src/requests/collection/server.ts +++ b/src/requests/collection/server.ts @@ -3,6 +3,7 @@ import { API_ENDPOINTS } from '@/shared/configs/endpoint' import { httpServer } from '@/shared/lib/axios/http-server' +/** server에서만 사용 */ export const getBookmarkedCollections = async () => { try { const { data } = await httpServer.get( diff --git a/src/requests/document/client.tsx b/src/requests/document/client.tsx index 376caeac..ab855d94 100644 --- a/src/requests/document/client.tsx +++ b/src/requests/document/client.tsx @@ -8,6 +8,7 @@ type GetDocumentsParams = { sortOption?: Document.Sort } +/** client에서만 사용 */ export const fetchDocuments = async (params?: GetDocumentsParams) => { const defaultSortOption = 'CREATED_AT' @@ -30,7 +31,7 @@ export const fetchDocuments = async (params?: GetDocumentsParams) => { } } -// document id page 컴포넌트에서도 사용됨 수정 필요 +/** client에서만 사용 */ export const fetchDocumentDetail = async (documentId?: number) => { if (documentId === null || documentId === undefined) return diff --git a/src/requests/document/server.ts b/src/requests/document/server.ts index cb12aa07..b0707380 100644 --- a/src/requests/document/server.ts +++ b/src/requests/document/server.ts @@ -8,7 +8,8 @@ type GetDocumentsParams = { sortOption?: Document.Sort } -export const fetchDocumentsServer = async (params?: GetDocumentsParams) => { +/** server에서만 사용 */ +export const fetchDocuments = async (params?: GetDocumentsParams) => { const defaultSortOption = 'CREATED_AT' const DocsParams = @@ -32,3 +33,18 @@ export const fetchDocumentsServer = async (params?: GetDocumentsParams) => { throw error } } + +/** server에서만 사용 */ +export const fetchDocumentDetail = async (documentId?: number) => { + if (documentId === null || documentId === undefined) return + + try { + const { data } = await httpServer.get( + API_ENDPOINTS.DOCUMENT.GET.BY_ID(documentId) + ) + return data + } catch (error: unknown) { + console.error(error) + throw error + } +} diff --git a/src/requests/quiz/client.tsx b/src/requests/quiz/client.tsx index 9d31b0ff..0db7eac5 100644 --- a/src/requests/quiz/client.tsx +++ b/src/requests/quiz/client.tsx @@ -55,7 +55,7 @@ export const fetchQuizSetRecord = async ({ quizSetType, }: { quizSetId: string - quizSetType: Quiz.SetType + quizSetType: Quiz.Set.Type }) => { try { const { data } = await http.get( diff --git a/src/requests/quiz/hooks.ts b/src/requests/quiz/hooks.ts index 659bd4ce..83a2330c 100644 --- a/src/requests/quiz/hooks.ts +++ b/src/requests/quiz/hooks.ts @@ -11,7 +11,7 @@ import { import { getQueryClient } from '@/shared/lib/tanstack-query/client' import { queries } from '@/shared/lib/tanstack-query/query-keys' -// 사용되는 곳 없음 (검토 후 삭제) +// 아직 사용처 없음 - 검토 필요 // export const useTodayQuizSetId = () => { // return useQuery({ // queryKey: ['todayQuizSetId'], diff --git a/src/requests/quiz/server.tsx b/src/requests/quiz/server.tsx index 66d94071..e373d847 100644 --- a/src/requests/quiz/server.tsx +++ b/src/requests/quiz/server.tsx @@ -21,7 +21,7 @@ export const fetchQuizSetById = async ({ }: { quizSetId: string collectionId?: number - quizSetType: Quiz.SetType + quizSetType: Quiz.Set.Type }) => { const params = collectionId ? { 'collection-id': collectionId, 'quiz-set-type': quizSetType } diff --git a/src/shared/configs/endpoint.ts b/src/shared/configs/endpoint.ts index 9f4b2913..b0af8dbe 100644 --- a/src/shared/configs/endpoint.ts +++ b/src/shared/configs/endpoint.ts @@ -152,7 +152,7 @@ export const API_ENDPOINTS = { /** GET /quizzes - 생성된 모든 퀴즈 가져오기(전체 문서) */ ALL: '/quizzes', /** GET /quizzes/{quiz_set_id}/{quiz_set_type}/quiz-record - 퀴즈 세트에 대한 상세 기록 */ - RECORD: (quizSetId: string, quizSetType: Quiz.SetType) => + RECORD: (quizSetId: string, quizSetType: Quiz.Set.Type) => `/quizzes/${quizSetId}/${quizSetType}/quiz-record`, /** GET /quizzes/quiz-records - 전체 퀴즈 기록 */ ALL_RECORDS: '/quizzes/quiz-records', diff --git a/src/shared/lib/tanstack-query/query-keys.ts b/src/shared/lib/tanstack-query/query-keys.ts index b4164e05..2ee919eb 100644 --- a/src/shared/lib/tanstack-query/query-keys.ts +++ b/src/shared/lib/tanstack-query/query-keys.ts @@ -32,7 +32,7 @@ export const queries = createQueryKeyStore({ queryFn: () => REQUEST.quiz.fetchDocumentQuizzes(params), enabled: !!params.documentId, }), - setRecord: (params: { quizSetId: string; quizSetType: Quiz.SetType }) => ({ + setRecord: (params: { quizSetId: string; quizSetType: Quiz.Set.Type }) => ({ queryKey: [params], queryFn: () => REQUEST.quiz.fetchQuizSetRecord(params), enabled: !!params.quizSetId, diff --git a/src/types/collection.d.ts b/src/types/collection.d.ts index a931ecbf..08a156dc 100644 --- a/src/types/collection.d.ts +++ b/src/types/collection.d.ts @@ -19,6 +19,8 @@ declare global { type Item = DeepRequired type Field = CollectionField + type SearchedCollection = DeepRequired + declare namespace Request { /** PATCH /api/v2/collections/{collection_id}/update-quizzes * 컬렉션 문제 편집 diff --git a/src/types/document.d.ts b/src/types/document.d.ts index 9f60cccc..e2fabd08 100644 --- a/src/types/document.d.ts +++ b/src/types/document.d.ts @@ -1,100 +1,17 @@ import { DeepRequired } from 'react-hook-form' import { components, paths } from './schema' -type DirectoryInDocument = Pick & { emoji?: string } - -type SortOption = 'CREATED_AT' | 'UPDATED_AT' - -type CreateType = 'TEXT' | 'FILE' | 'NOTION' - -type DocumentStatus = - | 'UNPROCESSED' - | 'PROCESSED' - | 'PROCESSING' - | 'COMPLETELY_FAILED' - | 'PARTIAL_SUCCESS' - | 'KEYPOINT_UPDATE_POSSIBLE' - | 'DEFAULT_DOCUMENT' - -type QuizType = 'MIX_UP' | 'MULTIPLE_CHOICE' - -type QuizItem = { - id: number - question: string - answer: string - explanation: string - options?: string[] - quizType: QuizType -} - -type DocumentBase = { - id: number - documentType: CreateType - status: DocumentStatus - totalQuizCount: number - characterCount: number - directory: DirectoryInDocument - updatedAt: string -} - -type DocumentDetailItem = DocumentBase & { - documentName: string - content: string - quizzes: QuizItem[] -} - -type DocumentListItem = DocumentBase & { - name: string - documentType: CreateType - previewContent: string - createdAt: string - reviewNeededQuizCount: number -} - -type SearchedDocument = { - documentId: number - documentName: string - content: string - directory: DirectoryInDocument -} - -type SearchedQuiz = { - id: number - question: string - answer: string - documentName: string - directoryName: string -} - -type CollectionField = - | 'IT' - | 'LAW' - | 'BUSINESS_ECONOMY' - | 'SOCIETY_POLITICS' - | 'LANGUAGE' - | 'MEDICINE_PHARMACY' - | 'ART' - | 'SCIENCE_ENGINEERING' - | 'HISTORY_PHILOSOPHY' - | 'OTHER' - -type SearchedCollection = { - id: number - name: string - emoji: string - bookmarkCount: number - collectionField: CollectionField - memberName: string - quizCount: number -} - declare global { declare namespace Document { - type DetailItem = DocumentDetailItem - type ItemInList = DocumentListItem - type List = DocumentListItem[] - type Status = DocumentStatus - type Sort = SortOption + type DetailItem = DeepRequired + type ItemInList = DeepRequired + type List = Document.ItemInList[] + type Sort = 'CREATED_AT' | 'UPDATED_AT' + + type Status = DeepRequired + type Type = DeepRequired + + type SearchedDocument = DeepRequired declare namespace Request { /** PATCH /api/v2/documents/{document_id}/update-name diff --git a/src/types/quiz.d.ts b/src/types/quiz.d.ts index 9fb3d924..6bc714d2 100644 --- a/src/types/quiz.d.ts +++ b/src/types/quiz.d.ts @@ -1,51 +1,48 @@ import { DeepRequired } from 'react-hook-form' import { components, paths } from './schema' -type ReplayQuizType = 'RANDOM' | 'MIX_UP' | 'MULTIPLE_CHOICE' - -type QuizItem = { - id: number - question: string - answer: string - explanation: string - quizType: 'MIX_UP' | 'MULTIPLE_CHOICE' - options?: string[] - answer?: 'correct' | 'incorrect' -} +/** 객체에서 특정 키를 옵셔널 처리해주는 타입 */ +type MakeOptional = Omit & Partial> -type DocumentInQuiz = DeepRequired -type DirectoryInQuiz = DeepRequired +type BaseQuizItem = DeepRequired +type QuizItem = MakeOptional -type QuizWithMetadata = { - document: DocumentInQuiz - directory: DirectoryInQuiz -} & QuizItem +type QuizType = Exclude, undefined> -// 처리 필요 -type ConsecutiveDays = { - currentConsecutiveDays: number - maxConsecutiveDays: number +type Metadata = { + document: DeepRequired + directory: DeepRequired } declare global { + /** <참고> + * OX : correct/incorrect + * 정답/오답 : right/wrong + */ declare namespace Quiz { type Item = QuizItem type List = QuizItem[] - type ItemWithMetadata = QuizWithMetadata + type ItemWithMetadata = QuizItem & Metadata - type Type = Exclude, undefined> + type Type = QuizType + type ReplayType = QuizType | 'RANDOM' type OXAnswer = 'correct' | 'incorrect' - type SetRecord = DeepRequired - type Record = DeepRequired + type Condition = 'IDLE' | 'DISABLED' | 'RIGHT' | 'WRONG' type Result = Quiz.Request.UpdateQuizResult['quizzes'][number] - type SetType = Exclude< - DeepRequired, - undefined - > + type Record = DeepRequired - type Condition = 'IDLE' | 'DISABLED' | 'RIGHT' | 'WRONG' + type SearchedQuiz = DeepRequired + + declare namespace Set { + type Type = Exclude< + DeepRequired, + undefined + > + + type Record = DeepRequired + } declare namespace Request { /** PATCH /api/v2/quiz/result