feature/qna #90
@ -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)
|
||||
|
||||
@ -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)
|
||||
@ -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"
|
||||
|
||||
@ -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 ?? [],
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user