feat: Add synchronous creation of single FAQ entry and duplicate question detection, update API documentation and frontend handling
This commit is contained in:
@@ -154,6 +154,10 @@ export function upsertFAQEntries(kbId: string, data: { entries: any[]; mode: 'ap
|
||||
return post(`/api/v1/knowledge-bases/${kbId}/faq/entries`, data);
|
||||
}
|
||||
|
||||
export function createFAQEntry(kbId: string, data: any) {
|
||||
return post(`/api/v1/knowledge-bases/${kbId}/faq/entry`, data);
|
||||
}
|
||||
|
||||
export function updateFAQEntry(kbId: string, entryId: string, data: any) {
|
||||
return put(`/api/v1/knowledge-bases/${kbId}/faq/entries/${entryId}`, data);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,16 @@ instance.interceptors.response.use(
|
||||
|
||||
const { status, data } = error.response;
|
||||
// 将HTTP状态码一并抛出,方便上层判断401等场景
|
||||
return Promise.reject({ status, ...(typeof data === 'object' ? data : { message: data }) });
|
||||
// 后端返回格式: { success: false, error: { code, message, details } }
|
||||
// 提取 error.message 作为顶层 message,方便前端使用 error?.message 获取
|
||||
const errorMessage = typeof data === 'object' && data?.error?.message
|
||||
? data.error.message
|
||||
: (typeof data === 'object' ? data?.message : data);
|
||||
return Promise.reject({
|
||||
status,
|
||||
message: errorMessage,
|
||||
...(typeof data === 'object' ? data : {})
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -1087,6 +1087,7 @@ import { useRouter } from 'vue-router'
|
||||
import {
|
||||
listFAQEntries,
|
||||
upsertFAQEntries,
|
||||
createFAQEntry,
|
||||
updateFAQEntry,
|
||||
updateFAQEntryStatusBatch,
|
||||
deleteFAQEntries,
|
||||
@@ -1908,10 +1909,7 @@ const handleSubmitEntry = async () => {
|
||||
tag_id: editorForm.tag_id || '',
|
||||
}
|
||||
if (editorMode.value === 'create') {
|
||||
await upsertFAQEntries(props.kbId, {
|
||||
entries: [payload],
|
||||
mode: 'append',
|
||||
})
|
||||
await createFAQEntry(props.kbId, payload)
|
||||
MessagePlugin.success(t('knowledgeEditor.messages.createSuccess'))
|
||||
} else if (currentEntryId.value) {
|
||||
await updateFAQEntry(props.kbId, currentEntryId.value, payload)
|
||||
|
||||
Reference in New Issue
Block a user