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 {
|
||||
@@ -115,7 +116,7 @@ export function mapUIToReviewStatus(status: string): number {
|
||||
* @param userId 用户ID
|
||||
* @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;
|
||||
error?: string;
|
||||
status?: number;
|
||||
@@ -135,34 +136,32 @@ export async function updateDocumentAuditStatus(id: string, auditStatus: number,
|
||||
userId
|
||||
});
|
||||
|
||||
const response = await postgrestPut<Document, Partial<Document>>(
|
||||
'/api/postgrest/proxy/documents',
|
||||
{ audit_status: auditStatus },
|
||||
{
|
||||
id: parseInt(id),
|
||||
user_id: parseInt(userId) // 确保只能更新自己的文档
|
||||
}
|
||||
);
|
||||
try {
|
||||
await axios.put(
|
||||
`${API_BASE_URL}/api/documents/${id}`,
|
||||
{ auditStatus },
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(frontendJWT ? { 'Authorization': `Bearer ${frontendJWT}` } : {})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// console.log('📝 [updateDocumentAuditStatus] postgrestPut响应:', response);
|
||||
|
||||
if (response.error) {
|
||||
console.warn('⚠️ [updateDocumentAuditStatus] postgrestPut返回错误,但操作可能已成功:', response.error);
|
||||
|
||||
// 更新操作具有幂等性,即使报错也可能已经成功
|
||||
// 返回成功,避免误报错误影响用户体验
|
||||
// 下次刷新时会显示最新状态
|
||||
console.log('✅ [updateDocumentAuditStatus] 新后端更新成功');
|
||||
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) {
|
||||
console.error('❌ [updateDocumentAuditStatus] 更新文件审核状态异常:', error);
|
||||
|
||||
// 即使捕获异常,更新操作可能已成功
|
||||
// 返回成功避免误报
|
||||
return { success: true };
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '更新文件审核状态失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user