fix(ai): correct double-wrap in OCR engine endpoints causing e.map error
Controller was returning { data: engines } which TransformInterceptor
wrapped again into { data: { data: engines } }. extractData() only peeled
one layer, leaving an object instead of the array — causing .map() to fail
in OcrEngineSelector.
- Return data directly from getOcrEngines() and selectOcrEngine()
- Add Array.isArray guard in OcrEngineSelector as defensive layer
This commit is contained in:
@@ -1041,12 +1041,11 @@ export class AiController {
|
|||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary: 'OCR Engines — ดึงรายการเอนจิน OCR ทั้งหมดที่มีในระบบ (T003)',
|
summary: 'OCR Engines — ดึงรายการเอนจิน OCR ทั้งหมดที่มีในระบบ (T003)',
|
||||||
})
|
})
|
||||||
async getOcrEngines(): Promise<{ data: OcrEngineResponseDto[] }> {
|
async getOcrEngines(): Promise<OcrEngineResponseDto[]> {
|
||||||
if (!this.ocrService) {
|
if (!this.ocrService) {
|
||||||
throw new SystemException('OcrService not injected in AiController');
|
throw new SystemException('OcrService not injected in AiController');
|
||||||
}
|
}
|
||||||
const engines = await this.ocrService.getOcrEngines();
|
return this.ocrService.getOcrEngines();
|
||||||
return { data: engines };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('ocr-engines/:engineId/select')
|
@Post('ocr-engines/:engineId/select')
|
||||||
@@ -1064,14 +1063,10 @@ export class AiController {
|
|||||||
async selectOcrEngine(
|
async selectOcrEngine(
|
||||||
@Param('engineId', ParseUuidPipe) engineId: string,
|
@Param('engineId', ParseUuidPipe) engineId: string,
|
||||||
@CurrentUser() user: User
|
@CurrentUser() user: User
|
||||||
): Promise<{ data: OcrEngineConfiguration }> {
|
): Promise<OcrEngineConfiguration> {
|
||||||
if (!this.ocrService) {
|
if (!this.ocrService) {
|
||||||
throw new SystemException('OcrService not injected in AiController');
|
throw new SystemException('OcrService not injected in AiController');
|
||||||
}
|
}
|
||||||
const engine = await this.ocrService.selectOcrEngine(
|
return this.ocrService.selectOcrEngine(engineId, user.user_id);
|
||||||
engineId,
|
|
||||||
user.user_id
|
|
||||||
);
|
|
||||||
return { data: engine };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default function OcrEngineSelector() {
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const data = await adminAiService.getOcrEngines();
|
const data = await adminAiService.getOcrEngines();
|
||||||
setEngines(data);
|
setEngines(Array.isArray(data) ? data : []);
|
||||||
} catch (_err: unknown) {
|
} catch (_err: unknown) {
|
||||||
toast.error('ไม่สามารถดึงข้อมูล OCR Engines ได้');
|
toast.error('ไม่สามารถดึงข้อมูล OCR Engines ได้');
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user