feature/qna #90

Merged
seul merged 5 commits from feature/qna into dev 2025-07-03 13:38:33 +09:00
4 changed files with 75 additions and 67 deletions
Showing only changes of commit d7b26be3cc - Show all commits

View File

@ -1,12 +1,15 @@
import { NextRequest, NextResponse } from 'next/server'
import { loggerWrapper } from '@/libs/api-wrapper'
import { prisma } from '@/libs/prisma'
import type { CommCode } from '@/types/CommCode'
import { CommonCode } from '@/types/Inquiry'
async function getCommCode(request: NextRequest): Promise<NextResponse> {
try {
const searchParams = request.nextUrl.searchParams
const headCode = searchParams.get('headCode')
if (headCode === 'QNA_CD') {
return getQnaCd()
}
// @ts-ignore
const headCd = await prisma.BC_COMM_H.findFirst({
@ -24,23 +27,22 @@ async function getCommCode(request: NextRequest): Promise<NextResponse> {
if (headCode === 'SALES_OFFICE_CD') {
return getSaleOffice(headCd.HEAD_CD)
} else {
// @ts-ignore
const roofMaterials: CommCode[] = await prisma.BC_COMM_L.findMany({
where: {
HEAD_CD: headCd.HEAD_CD,
},
select: {
HEAD_CD: true,
CODE: true,
CODE_JP: true,
},
orderBy: {
CODE: 'asc',
},
})
return NextResponse.json(roofMaterials)
}
// @ts-ignore
const roofMaterials: CommCode[] = await prisma.BC_COMM_L.findMany({
where: {
HEAD_CD: headCd.HEAD_CD,
},
select: {
HEAD_CD: true,
CODE: true,
CODE_JP: true,
},
orderBy: {
CODE: 'asc',
},
})
return NextResponse.json(roofMaterials)
} catch (error) {
console.error('❌ 데이터 조회 중 오류가 발생했습니다:', error)
return NextResponse.json({ error: '데이터 조회 중 오류가 발생했습니다' }, { status: 500 })
@ -64,4 +66,50 @@ const getSaleOffice = async (headCode: string) => {
return NextResponse.json(commCodeSaleOffice)
}
/**
* @description QNA
* @returns {CommonCode[]} QNA
*/
const getQnaCd = async () => {
// @ts-ignore
const headCdList: { HEAD_CD: string; HEAD_ID: string }[] = await prisma.BC_COMM_H.findMany({
where: {
OR: [{ HEAD_ID: { in: ['QNA_CLS_LRG_CD'] } }, { HEAD_ID: { in: ['QNA_CLS_MID_CD'] } }, { HEAD_ID: { in: ['QNA_CLS_SML_CD'] } }],
},
select: {
HEAD_CD: true,
HEAD_ID: true,
},
})
const result: CommonCode[] = []
// @ts-ignore
const commCodeQna: CommCode[] = await prisma.BC_COMM_L.findMany({
where: {
HEAD_CD: {
in: headCdList.map((item) => item.HEAD_CD).filter(Boolean),
},
},
select: {
HEAD_CD: true,
CODE: true,
CODE_JP: true,
REF_CHR1: true,
},
})
commCodeQna.forEach((item) => {
result.push({
// @ts-ignore
headCd: item.HEAD_CD,
// @ts-ignore
headId: headCdList.find((headCd) => headCd.HEAD_CD === item.HEAD_CD)?.HEAD_ID ?? '',
// @ts-ignore
code: item.CODE,
// @ts-ignore
name: item.CODE_JP,
// @ts-ignore
refChar1: item.REF_CHR1 ?? '',
})
})
return NextResponse.json(result)
}
export const GET = loggerWrapper(getCommCode)

View File

@ -1,45 +0,0 @@
import { NextResponse } from 'next/server'
import axios from 'axios'
import { loggerWrapper } from '@/libs/api-wrapper'
import { QnaService } from './service'
import { ApiError } from 'next/dist/server/api-utils'
/**
* @api {GET} /api/qna API
* @apiName GET /api/qna
* @apiGroup Qna
* @apiDescription API
*
* @apiSuccess {Object} data
* @apiSuccess {String} data.headCd
* @apiSuccess {String} data.code
* @apiSuccess {String} data.codeJp -
* @apiSuccess {String} data.refChr1 -
*
* @apiExample {curl} Example usage:
* curl -X GET http://localhost:3000/api/qna
*
* @apiSuccessExample {json} Success-Response:
* {
* "data": [
* {
* "headCd": "204200",
* "code": "1",
* "codeJp": "1",
* "refChr1": "1"
* }
* ],
* ...
* }
*/
async function getCommonCodeListData(): Promise<NextResponse> {
const service = new QnaService()
const response = await service.tryFunction(() => axios.get(`${process.env.NEXT_PUBLIC_INQUIRY_API_URL}/api/system/commonCodeListData`))
if (response instanceof ApiError) {
return NextResponse.json({ error: response.message }, { status: response.statusCode })
}
const result = service.getInquiryTypeList(response.data)
return NextResponse.json({ data: result })
}
export const GET = loggerWrapper(getCommonCodeListData)

View File

@ -161,7 +161,7 @@ export default function RegistForm() {
))}
</select>
</div>
{commonCodeList.filter((code) => code.refChar1 === inquiryRequest.qnaClsLrgCd).length > 0 && (
{commonCodeList.filter((code) => code.refChar1 === inquiryRequest.qnaClsLrgCd).length > 0 && inquiryRequest.qnaClsLrgCd && (
<div className="data-input mt5">
<select
className="select-form"
@ -183,7 +183,7 @@ export default function RegistForm() {
</select>
</div>
)}
{commonCodeList.filter((code) => code.refChar1 === inquiryRequest.qnaClsMidCd).length > 0 && (
{commonCodeList.filter((code) => code.refChar1 === inquiryRequest.qnaClsMidCd).length > 0 && inquiryRequest.qnaClsMidCd && (
<div className="data-input mt5">
<select
className="select-form"

View File

@ -5,6 +5,7 @@ import { useInquiryFilterStore } from '@/store/inquiryFilterStore'
import { useMemo } from 'react'
import { useRouter } from 'next/navigation'
import { useAlertMsg } from '@/hooks/useAlertMsg'
import { CommCode } from '@/types/CommCode'
/**
* @description
@ -227,8 +228,12 @@ export function useInquiry(
const isListQuery = false
const shouldThrowError = false
const resp = await tryFunction(() => axiosInstance(null).get<{ data: CommonCode[] }>(`/api/qna`), isListQuery, shouldThrowError)
return resp.data
const resp = await tryFunction(
() => axiosInstance(null).get<CommonCode[]>('/api/comm-code', { params: { headCode: 'QNA_CD' } }),
isListQuery,
shouldThrowError,
)
return resp?.data ?? []
},
staleTime: Infinity,
gcTime: Infinity,
@ -242,6 +247,6 @@ export function useInquiry(
isSavingInquiry,
saveInquiry,
downloadFile,
commonCodeList: commonCodeList?.data ?? [],
commonCodeList: commonCodeList ?? [],
}
}