fix(ai): correct double-wrap in OCR engine endpoints causing e.map error
CI / CD Pipeline / build (push) Successful in 4m50s
CI / CD Pipeline / deploy (push) Successful in 14m18s

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:
2026-06-02 15:49:39 +07:00
parent e4948ad4c8
commit 754d609399
2 changed files with 5 additions and 10 deletions
+4 -9
View File
@@ -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 {