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({
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user