fix: 지붕재적합성 detail 데이터 없는 경우 방어처리 추가
This commit is contained in:
parent
7fd1be2cc4
commit
25cbd92a55
@ -12,7 +12,7 @@ import { Suitable } from '@/types/Suitable'
|
|||||||
*
|
*
|
||||||
* @apiBody {FormData} form-data
|
* @apiBody {FormData} form-data
|
||||||
* @apiBody {String} form-data.ids 메인 ID 목록 (쉼표로 구분된 문자열)
|
* @apiBody {String} form-data.ids 메인 ID 목록 (쉼표로 구분된 문자열)
|
||||||
* @apiBody {String} form-data.detailIds 상세 ID 목록 (쉼표로 구분된 문자열)
|
* @apiBody {String} [form-data.detailIds] 상세 ID 목록 (쉼표로 구분된 문자열)
|
||||||
*
|
*
|
||||||
* @apiExample {curl} Example usage:
|
* @apiExample {curl} Example usage:
|
||||||
* curl -X POST \
|
* curl -X POST \
|
||||||
@ -44,10 +44,10 @@ export async function POST(request: NextRequest) {
|
|||||||
try {
|
try {
|
||||||
const body: Record<string, string> = await request.json()
|
const body: Record<string, string> = await request.json()
|
||||||
const ids = body.ids
|
const ids = body.ids
|
||||||
const detailIds = body.detailIds
|
const detailIds = body.detailIds || ''
|
||||||
|
|
||||||
/* 파라미터 체크 */
|
/* 파라미터 체크 */
|
||||||
if (ids === '' || detailIds === '') {
|
if (ids === '') {
|
||||||
return NextResponse.json({ error: '필수 파라미터가 누락되었습니다' }, { status: 400 })
|
return NextResponse.json({ error: '필수 파라미터가 누락되었습니다' }, { status: 400 })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ export async function POST(request: NextRequest) {
|
|||||||
, msd_json.memo
|
, msd_json.memo
|
||||||
FROM ms_suitable_detail msd_json
|
FROM ms_suitable_detail msd_json
|
||||||
WHERE msd.main_id = msd_json.main_id
|
WHERE msd.main_id = msd_json.main_id
|
||||||
AND msd_json.id IN (:detailIds)
|
--detailIds AND msd_json.id IN (:detailIds)
|
||||||
FOR JSON PATH
|
FOR JSON PATH
|
||||||
) AS detail
|
) AS detail
|
||||||
FROM ms_suitable_detail msd
|
FROM ms_suitable_detail msd
|
||||||
@ -86,7 +86,10 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
/* 검색 조건 설정 */
|
/* 검색 조건 설정 */
|
||||||
query = query.replaceAll(':mainIds', ids)
|
query = query.replaceAll(':mainIds', ids)
|
||||||
query = query.replaceAll(':detailIds', detailIds)
|
if (detailIds) {
|
||||||
|
query = query.replace('--detailIds ', '')
|
||||||
|
query = query.replace(':detailIds', detailIds)
|
||||||
|
}
|
||||||
|
|
||||||
const suitable: Suitable[] = await prisma.$queryRawUnsafe(query)
|
const suitable: Suitable[] = await prisma.$queryRawUnsafe(query)
|
||||||
|
|
||||||
|
|||||||
@ -68,7 +68,7 @@ export default function SuitableDetailPopup() {
|
|||||||
<div className="check-pop-data-txt">{toCodeName(SUITABLE_HEAD_CODE.ROOF_SH_CD, item.roofShCd)}</div>
|
<div className="check-pop-data-txt">{toCodeName(SUITABLE_HEAD_CODE.ROOF_SH_CD, item.roofShCd)}</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="check-pop-data-table-wrap">
|
<div className="check-pop-data-table-wrap">
|
||||||
{toSuitableDetail(item.detail).map((subItem: SuitableDetail) => (
|
{toSuitableDetail(item.detail)?.map((subItem: SuitableDetail) => (
|
||||||
<div className="check-pop-data-table" key={subItem.id}>
|
<div className="check-pop-data-table" key={subItem.id}>
|
||||||
<div className="pop-data-table-head">
|
<div className="pop-data-table-head">
|
||||||
<div className="pop-data-table-head-name">{toCodeName(SUITABLE_HEAD_CODE.TRESTLE_MFPC_CD, subItem.trestleMfpcCd)}</div>
|
<div className="pop-data-table-head-name">{toCodeName(SUITABLE_HEAD_CODE.TRESTLE_MFPC_CD, subItem.trestleMfpcCd)}</div>
|
||||||
|
|||||||
@ -83,7 +83,7 @@ export default function SuitableList() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul className="reference-list check">
|
<ul className="reference-list check">
|
||||||
{toSuitableDetail(item.detail).map((subItem: SuitableDetail) => (
|
{toSuitableDetail(item.detail)?.map((subItem: SuitableDetail) => (
|
||||||
<li className="reference-item" key={subItem.id}>
|
<li className="reference-item" key={subItem.id}>
|
||||||
<div className="check-item-wrap">
|
<div className="check-item-wrap">
|
||||||
<div className="check-form-box light">
|
<div className="check-form-box light">
|
||||||
|
|||||||
@ -84,7 +84,7 @@ export function useSuitable() {
|
|||||||
const getSuitableDetails = async (ids: string, detailIds?: string): Promise<Suitable[]> => {
|
const getSuitableDetails = async (ids: string, detailIds?: string): Promise<Suitable[]> => {
|
||||||
try {
|
try {
|
||||||
const params: Record<string, string> = { ids: ids }
|
const params: Record<string, string> = { ids: ids }
|
||||||
if (detailIds) params.detailIds = detailIds
|
if (detailIds?.trim()) params.detailIds = detailIds
|
||||||
const response = await axiosInstance(null).post<Suitable[]>('/api/suitable', params)
|
const response = await axiosInstance(null).post<Suitable[]>('/api/suitable', params)
|
||||||
return response.data
|
return response.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -150,6 +150,7 @@ export function useSuitable() {
|
|||||||
*/
|
*/
|
||||||
const toSuitableDetailIds = (suitableDetailString: string): Set<number> => {
|
const toSuitableDetailIds = (suitableDetailString: string): Set<number> => {
|
||||||
try {
|
try {
|
||||||
|
if (!suitableDetailString) return new Set()
|
||||||
return new Set<number>(JSON.parse(suitableDetailString).map(({ id }: { id: number }) => id))
|
return new Set<number>(JSON.parse(suitableDetailString).map(({ id }: { id: number }) => id))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`지붕재 적합성 detail 데이터 파싱 실패: ${error}`)
|
console.error(`지붕재 적합성 detail 데이터 파싱 실패: ${error}`)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user