Skip to content

Commit

Permalink
fix: type
Browse files Browse the repository at this point in the history
  • Loading branch information
rabyeoljji committed Dec 10, 2024
1 parent 6d34383 commit c9c232a
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 134 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"remirror",
"svgs",
"swipeable",
"taglib",
"Tanstack",
"Uncapitalize",
"vaul",
Expand Down
2 changes: 1 addition & 1 deletion src/app/(routes)/document/[id]/(main)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions src/app/(routes)/main/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion src/features/quiz/screen/quiz-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const QuizView = ({ quizzes, isFirst }: Props) => {
<QuizExplanationDrawer
isRight={currentResult.answer}
rightAnswer={
currentQuiz.quizType === 'MULTIPLE_CHOICE'
currentQuiz.quizType === 'MULTIPLE_CHOICE' && currentQuiz.options
? currentQuiz.options.find((option) => option === currentQuiz.answer)!
: currentQuiz.answer === 'correct'
? 'O'
Expand Down
2 changes: 1 addition & 1 deletion src/features/quiz/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
1 change: 1 addition & 0 deletions src/requests/collection/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const getMyCollections = async () => {
}
}

/** client에서만 사용 */
export const getBookmarkedCollections = async () => {
try {
const { data } = await http.get<Collection.Response.GetBookmarkedCollections>(
Expand Down
1 change: 1 addition & 0 deletions src/requests/collection/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Collection.Response.GetBookmarkedCollections>(
Expand Down
3 changes: 2 additions & 1 deletion src/requests/document/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type GetDocumentsParams = {
sortOption?: Document.Sort
}

/** client에서만 사용 */
export const fetchDocuments = async (params?: GetDocumentsParams) => {
const defaultSortOption = 'CREATED_AT'

Expand All @@ -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

Expand Down
18 changes: 17 additions & 1 deletion src/requests/document/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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<Document.DetailItem>(
API_ENDPOINTS.DOCUMENT.GET.BY_ID(documentId)
)
return data
} catch (error: unknown) {
console.error(error)
throw error
}
}
2 changes: 1 addition & 1 deletion src/requests/quiz/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const fetchQuizSetRecord = async ({
quizSetType,
}: {
quizSetId: string
quizSetType: Quiz.SetType
quizSetType: Quiz.Set.Type
}) => {
try {
const { data } = await http.get<Quiz.Response.GetQuizSetRecord>(
Expand Down
2 changes: 1 addition & 1 deletion src/requests/quiz/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion src/requests/quiz/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/shared/configs/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/shared/lib/tanstack-query/query-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/types/collection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ declare global {
type Item = DeepRequired<components['schemas']['CollectionDto']>
type Field = CollectionField

type SearchedCollection = DeepRequired<components['schemas']['IntegratedSearchCollectionDto']>

declare namespace Request {
/** PATCH /api/v2/collections/{collection_id}/update-quizzes
* 컬렉션 문제 편집
Expand Down
101 changes: 9 additions & 92 deletions src/types/document.d.ts
Original file line number Diff line number Diff line change
@@ -1,100 +1,17 @@
import { DeepRequired } from 'react-hook-form'
import { components, paths } from './schema'

type DirectoryInDocument = Pick<Directory.Item, 'id' | 'name'> & { 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<components['schemas']['GetSingleDocumentResponse']>
type ItemInList = DeepRequired<components['schemas']['GetAllDocumentsDocumentDto']>
type List = Document.ItemInList[]
type Sort = 'CREATED_AT' | 'UPDATED_AT'

type Status = DeepRequired<components['schemas']['GetAllDocumentsDocumentDto']['status']>
type Type = DeepRequired<components['schemas']['GetAllDocumentsDocumentDto']['documentType']>

type SearchedDocument = DeepRequired<components['schemas']['IntegratedSearchDocumentDto']>

declare namespace Request {
/** PATCH /api/v2/documents/{document_id}/update-name
Expand Down
57 changes: 27 additions & 30 deletions src/types/quiz.d.ts
Original file line number Diff line number Diff line change
@@ -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<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>

type DocumentInQuiz = DeepRequired<components['schemas']['DocumentDto']>
type DirectoryInQuiz = DeepRequired<components['schemas']['DirectoryDto']>
type BaseQuizItem = DeepRequired<components['schemas']['QuizDto']>
type QuizItem = MakeOptional<BaseQuizItem, 'options'>

type QuizWithMetadata = {
document: DocumentInQuiz
directory: DirectoryInQuiz
} & QuizItem
type QuizType = Exclude<DeepRequired<components['schemas']['QuizDto']['quizType']>, undefined>

// 처리 필요
type ConsecutiveDays = {
currentConsecutiveDays: number
maxConsecutiveDays: number
type Metadata = {
document: DeepRequired<components['schemas']['DocumentDto']>
directory: DeepRequired<components['schemas']['DirectoryDto']>
}

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<DeepRequired<components['schemas']['QuizDto']['quizType']>, undefined>
type Type = QuizType
type ReplayType = QuizType | 'RANDOM'
type OXAnswer = 'correct' | 'incorrect'

type SetRecord = DeepRequired<components['schemas']['GetSingleQuizSetRecordDto']>
type Record = DeepRequired<components['schemas']['GetQuizRecordDto']>
type Condition = 'IDLE' | 'DISABLED' | 'RIGHT' | 'WRONG'
type Result = Quiz.Request.UpdateQuizResult['quizzes'][number]

type SetType = Exclude<
DeepRequired<components['schemas']['GetQuizRecordDto']['quizSetType']>,
undefined
>
type Record = DeepRequired<components['schemas']['GetQuizRecordDto']>

type Condition = 'IDLE' | 'DISABLED' | 'RIGHT' | 'WRONG'
type SearchedQuiz = DeepRequired<components['schemas']['IntegratedSearchQuizDto']>

declare namespace Set {
type Type = Exclude<
DeepRequired<components['schemas']['GetQuizRecordDto']['quizSetType']>,
undefined
>

type Record = DeepRequired<components['schemas']['GetSingleQuizSetRecordDto']>
}

declare namespace Request {
/** PATCH /api/v2/quiz/result
Expand Down

0 comments on commit c9c232a

Please sign in to comment.