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({
summary: 'OCR Engines — ดึงรายการเอนจิน OCR ทั้งหมดที่มีในระบบ (T003)',
})
async getOcrEngines(): Promise<{ data: OcrEngineResponseDto[] }> {
async getOcrEngines(): Promise<OcrEngineResponseDto[]> {
if (!this.ocrService) {
throw new SystemException('OcrService not injected in AiController');
}
const engines = await this.ocrService.getOcrEngines();
return { data: engines };
return this.ocrService.getOcrEngines();
}
@Post('ocr-engines/:engineId/select')
@@ -1064,14 +1063,10 @@ export class AiController {
async selectOcrEngine(
@Param('engineId', ParseUuidPipe) engineId: string,
@CurrentUser() user: User
): Promise<{ data: OcrEngineConfiguration }> {
): Promise<OcrEngineConfiguration> {
if (!this.ocrService) {
throw new SystemException('OcrService not injected in AiController');
}
const engine = await this.ocrService.selectOcrEngine(
engineId,
user.user_id
);
return { data: engine };
return this.ocrService.selectOcrEngine(engineId, user.user_id);
}
}
@@ -22,7 +22,7 @@ export default function OcrEngineSelector() {
try {
setIsLoading(true);
const data = await adminAiService.getOcrEngines();
setEngines(data);
setEngines(Array.isArray(data) ? data : []);
} catch (_err: unknown) {
toast.error('ไม่สามารถดึงข้อมูล OCR Engines ได้');
} finally {