diff --git a/src/apis/certification.ts b/src/apis/certification.ts index 2705303..9bc09bc 100644 --- a/src/apis/certification.ts +++ b/src/apis/certification.ts @@ -15,7 +15,7 @@ export const postCertification = async ({ image, certificationSource, recycleGui formData.append('image', image); formData.append('certificationSource', certificationSource); - if (recycleGuideId !== null) { + if (recycleGuideId !== null && recycleGuideId !== undefined) { formData.append('recycleGuideId', recycleGuideId.toString()); } diff --git a/src/pages/cameara-page.tsx b/src/pages/cameara-page.tsx index 0e5777f..a2d7ab4 100644 --- a/src/pages/cameara-page.tsx +++ b/src/pages/cameara-page.tsx @@ -35,11 +35,10 @@ export default function CamearaPage() { try { const file = await base64ToFile(img); - // 신규 인증 - if (from === 'certification') { - const data = await postCertification({ image: file, certificationSource, recycleGuideId: guideId }); - - // 신규 인증 성공 + // 재인증 + if (certificationId) { + const data = await postCertificationRetry(certificationId, file); + // 재인증 성공 if (data.result?.status === 'PASSED') { navigate('/certification/success', { state: { @@ -49,7 +48,7 @@ export default function CamearaPage() { }, }); } - // 신규 인증 실패 + // 재인증 실패 else if (data.result?.status === 'FAILED') { // AI 판정 실패 if (data.result.failureType === 'VLM_JUDGEMENT_FAILED') { @@ -60,12 +59,10 @@ export default function CamearaPage() { retryGuide: data.result.retryGuide, retryAllowed: data.result.retryAllowed, certificationId: data.result.certificationId, - certificationSource, - guideId, }, }); } - // 동일 품목 인증 시도 + // 동일 품목 재인증 시도 else if (data.result.failureType === 'DUPLICATE_GUIDE_TODAY') { navigate('/certification/fail', { state: { @@ -74,34 +71,17 @@ export default function CamearaPage() { retryGuide: data.result.retryGuide, retryAllowed: data.result.retryAllowed, certificationId: data.result.certificationId, - certificationSource, - guideId, }, }); } } } - // 배출 정보 검색 - else if (from === 'info') { - const data = await postGuideImageSearch(file); - // 검색 성공 - if (data.result?.identified) { - navigate('/disposal-info/detail', { - state: { - guide: data.result?.guideDetail, - }, - }); - } - // 검색 실패 - else { - navigate('/disposal-info/fail'); - } - } - // 재인증 - else if (certificationId) { - const data = await postCertificationRetry(certificationId, file); - // 재인증 성공 + // 신규 인증 + else if (from === 'certification') { + const data = await postCertification({ image: file, certificationSource, recycleGuideId: guideId }); + + // 신규 인증 성공 if (data.result?.status === 'PASSED') { navigate('/certification/success', { state: { @@ -111,7 +91,7 @@ export default function CamearaPage() { }, }); } - // 재인증 실패 + // 신규 인증 실패 else if (data.result?.status === 'FAILED') { // AI 판정 실패 if (data.result.failureType === 'VLM_JUDGEMENT_FAILED') { @@ -122,10 +102,12 @@ export default function CamearaPage() { retryGuide: data.result.retryGuide, retryAllowed: data.result.retryAllowed, certificationId: data.result.certificationId, + certificationSource, + guideId, }, }); } - // 동일 품목 재인증 시도 + // 동일 품목 인증 시도 else if (data.result.failureType === 'DUPLICATE_GUIDE_TODAY') { navigate('/certification/fail', { state: { @@ -134,11 +116,30 @@ export default function CamearaPage() { retryGuide: data.result.retryGuide, retryAllowed: data.result.retryAllowed, certificationId: data.result.certificationId, + certificationSource, + guideId, }, }); } } } + // 배출 정보 검색 + else if (from === 'info') { + const data = await postGuideImageSearch(file); + + // 검색 성공 + if (data.result?.identified) { + navigate('/disposal-info/detail', { + state: { + guide: data.result?.guideDetail, + }, + }); + } + // 검색 실패 + else { + navigate('/disposal-info/fail'); + } + } } catch (e) { alert('접속이 원활하지 않습니다. 잠시 후 다시 시도해 주세요.'); console.error('camera error', e); diff --git a/src/pages/certification-page/fail-page.tsx b/src/pages/certification-page/fail-page.tsx index 566f18e..a5e1dfa 100644 --- a/src/pages/certification-page/fail-page.tsx +++ b/src/pages/certification-page/fail-page.tsx @@ -21,6 +21,7 @@ export default function FailPage() { if (failureType === 'VLM_JUDGEMENT_FAILED' && retryAllowed && certificationId) { navigate('/camera', { state: { + from: 'certification', certificationId, }, }); @@ -32,7 +33,6 @@ export default function FailPage() { from: 'certification', certificationSource, guideId, - // certificationId }, }); } else {