fix: remove document review status postgrest fallback
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { postgrestPut } from '../postgrest-client';
|
import axios from 'axios';
|
||||||
|
import { API_BASE_URL } from '~/config/api-config';
|
||||||
|
|
||||||
// 文档数据库表接口
|
// 文档数据库表接口
|
||||||
export interface Document {
|
export interface Document {
|
||||||
@@ -115,7 +116,7 @@ export function mapUIToReviewStatus(status: string): number {
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @returns 更新结果
|
* @returns 更新结果
|
||||||
*/
|
*/
|
||||||
export async function updateDocumentAuditStatus(id: string, auditStatus: number, userId: string): Promise<{
|
export async function updateDocumentAuditStatus(id: string, auditStatus: number, userId: string, frontendJWT?: string): Promise<{
|
||||||
success?: boolean;
|
success?: boolean;
|
||||||
error?: string;
|
error?: string;
|
||||||
status?: number;
|
status?: number;
|
||||||
@@ -135,34 +136,32 @@ export async function updateDocumentAuditStatus(id: string, auditStatus: number,
|
|||||||
userId
|
userId
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await postgrestPut<Document, Partial<Document>>(
|
try {
|
||||||
'/api/postgrest/proxy/documents',
|
await axios.put(
|
||||||
{ audit_status: auditStatus },
|
`${API_BASE_URL}/api/documents/${id}`,
|
||||||
{
|
{ auditStatus },
|
||||||
id: parseInt(id),
|
{
|
||||||
user_id: parseInt(userId) // 确保只能更新自己的文档
|
headers: {
|
||||||
}
|
'Content-Type': 'application/json',
|
||||||
);
|
...(frontendJWT ? { 'Authorization': `Bearer ${frontendJWT}` } : {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// console.log('📝 [updateDocumentAuditStatus] postgrestPut响应:', response);
|
console.log('✅ [updateDocumentAuditStatus] 新后端更新成功');
|
||||||
|
|
||||||
if (response.error) {
|
|
||||||
console.warn('⚠️ [updateDocumentAuditStatus] postgrestPut返回错误,但操作可能已成功:', response.error);
|
|
||||||
|
|
||||||
// 更新操作具有幂等性,即使报错也可能已经成功
|
|
||||||
// 返回成功,避免误报错误影响用户体验
|
|
||||||
// 下次刷新时会显示最新状态
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ [updateDocumentAuditStatus] 新后端更新失败:', error);
|
||||||
|
return {
|
||||||
|
error: error instanceof Error ? error.message : '更新文件审核状态失败',
|
||||||
|
status: axios.isAxiosError(error) ? error.response?.status || 500 : 500
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('✅ [updateDocumentAuditStatus] 更新成功');
|
|
||||||
return { success: true };
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ [updateDocumentAuditStatus] 更新文件审核状态异常:', error);
|
console.error('❌ [updateDocumentAuditStatus] 更新文件审核状态异常:', error);
|
||||||
|
return {
|
||||||
// 即使捕获异常,更新操作可能已成功
|
error: error instanceof Error ? error.message : '更新文件审核状态失败',
|
||||||
// 返回成功避免误报
|
status: 500
|
||||||
return { success: true };
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -804,7 +804,7 @@ export default function DocumentsIndex() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// console.log('开始审核',fileId,auditStatus)
|
// console.log('开始审核',fileId,auditStatus)
|
||||||
const response = await updateDocumentAuditStatus(fileId.toString(), 2, userId);
|
const response = await updateDocumentAuditStatus(fileId.toString(), 2, userId, loaderData.frontendJWT);
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error('更新文件审核状态失败:', response.error);
|
console.error('更新文件审核状态失败:', response.error);
|
||||||
toastService.error('更新文件审核状态失败:' + (response.error || '未知错误'));
|
toastService.error('更新文件审核状态失败:' + (response.error || '未知错误'));
|
||||||
|
|||||||
@@ -2089,7 +2089,7 @@ export default function FilesUpload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// console.log('【调试-handleViewFile】更新文件审核状态,文件ID:', record.id);
|
// console.log('【调试-handleViewFile】更新文件审核状态,文件ID:', record.id);
|
||||||
const response = await updateDocumentAuditStatus(record.id.toString(), 2, userId);
|
const response = await updateDocumentAuditStatus(record.id.toString(), 2, userId, loaderData.frontendJWT);
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error('【调试-handleViewFile】更新文件审核状态失败:', response.error);
|
console.error('【调试-handleViewFile】更新文件审核状态失败:', response.error);
|
||||||
toastService.error('更新文件审核状态失败:' + (response.error || '未知错误'));
|
toastService.error('更新文件审核状态失败:' + (response.error || '未知错误'));
|
||||||
|
|||||||
Reference in New Issue
Block a user