feat: [WEB] 중간검사 프론트엔드 저장 연동 (Phase 2)
- WorkerScreen/actions.ts에 saveItemInspection, getWorkOrderInspectionData 서버 액션 추가
- handleInspectionComplete에서 POST /items/{itemId}/inspection API 호출 연동
- 작업지시 선택 시 GET /inspection-data로 기존 검사 데이터 자동 로드
- InspectionInputModal에 initialData prop 추가 (재클릭 시 저장된 값 표시)
- WorkItemData에 apiItemId, workOrderId 필드 추가 (실제 DB ID 보존)
- 기존 saveInspectionData deprecated 처리
This commit is contained in:
@@ -827,4 +827,87 @@ export async function getWorkOrderDetail(
|
||||
console.error('[WorkerScreenActions] getWorkOrderDetail error:', error);
|
||||
return { success: false, data: [], error: '서버 오류' };
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 개소별 중간검사 데이터 저장 =====
|
||||
export async function saveItemInspection(
|
||||
workOrderId: string,
|
||||
itemId: number,
|
||||
processType: string,
|
||||
inspectionData: Record<string, unknown>
|
||||
): Promise<{ success: boolean; data?: Record<string, unknown>; error?: string }> {
|
||||
try {
|
||||
console.log('[WorkerScreenActions] POST item inspection:', { workOrderId, itemId, processType });
|
||||
|
||||
const { response, error } = await serverFetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/work-orders/${workOrderId}/items/${itemId}/inspection`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
process_type: processType,
|
||||
inspection_data: inspectionData,
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
if (error || !response) {
|
||||
return { success: false, error: error?.message || 'API 요청 실패' };
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
console.log('[WorkerScreenActions] POST item inspection response:', result);
|
||||
|
||||
if (!response.ok || !result.success) {
|
||||
return { success: false, error: result.message || '검사 데이터 저장에 실패했습니다.' };
|
||||
}
|
||||
|
||||
return { success: true, data: result.data };
|
||||
} catch (error) {
|
||||
if (isNextRedirectError(error)) throw error;
|
||||
console.error('[WorkerScreenActions] saveItemInspection error:', error);
|
||||
return { success: false, error: '서버 오류가 발생했습니다.' };
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 작업지시 전체 검사 데이터 조회 =====
|
||||
export interface InspectionDataItem {
|
||||
item_id: number;
|
||||
item_name: string;
|
||||
specification: string | null;
|
||||
quantity: number;
|
||||
sort_order: number;
|
||||
options: Record<string, unknown> | null;
|
||||
inspection_data: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export async function getWorkOrderInspectionData(
|
||||
workOrderId: string
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
data?: { work_order_id: number; items: InspectionDataItem[]; total: number };
|
||||
error?: string;
|
||||
}> {
|
||||
try {
|
||||
const url = `${process.env.NEXT_PUBLIC_API_URL}/api/v1/work-orders/${workOrderId}/inspection-data`;
|
||||
|
||||
console.log('[WorkerScreenActions] GET inspection data:', url);
|
||||
|
||||
const { response, error } = await serverFetch(url, { method: 'GET' });
|
||||
|
||||
if (error || !response) {
|
||||
return { success: false, error: error?.message || 'API 요청 실패' };
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok || !result.success) {
|
||||
return { success: false, error: result.message || '검사 데이터 조회에 실패했습니다.' };
|
||||
}
|
||||
|
||||
return { success: true, data: result.data };
|
||||
} catch (error) {
|
||||
if (isNextRedirectError(error)) throw error;
|
||||
console.error('[WorkerScreenActions] getWorkOrderInspectionData error:', error);
|
||||
return { success: false, error: '서버 오류가 발생했습니다.' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user