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