fix: 修复评查点分组的结果保存异常
This commit is contained in:
@@ -516,30 +516,57 @@ export async function createRuleGroup(groupData: RuleGroupCreateUpdateDto, token
|
||||
*/
|
||||
export async function updateRuleGroup(id: string, data: RuleGroupCreateUpdateDto, token?: string): Promise<{data: RuleGroup; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 验证必填字段
|
||||
if (!data.name || !data.code) {
|
||||
return { error: '分组名称和编码不能为空', status: 400 };
|
||||
}
|
||||
|
||||
// 根据 reviewType 确定 m_type 的值
|
||||
// contract -> 0, 其他 -> 1
|
||||
const mType = data.reviewType === 'contract' ? 0 : 1;
|
||||
|
||||
// 构建符合数据库结构的对象
|
||||
const apiGroup: Partial<ApiRuleGroup> = {
|
||||
name: data.name.trim(),
|
||||
code: data.code.trim(),
|
||||
description: data.description || '',
|
||||
is_enabled: data.is_enabled,
|
||||
m_type: mType // 使用 m_type 而不是 reviewType
|
||||
};
|
||||
|
||||
// 如果需要更新父分组,添加 pid
|
||||
if (data.pid !== undefined) {
|
||||
const pidValue = data.pid ? Number(data.pid) : 0;
|
||||
if (isNaN(pidValue)) {
|
||||
return { error: '父分组ID必须是有效的数字', status: 400 };
|
||||
}
|
||||
apiGroup.pid = pidValue;
|
||||
}
|
||||
|
||||
// 使用新的filters参数
|
||||
const response = await postgrestPut<ApiResponse<RuleGroup> | RuleGroup, RuleGroupCreateUpdateDto>(
|
||||
const response = await postgrestPut<ApiResponse<RuleGroup> | RuleGroup, Partial<ApiRuleGroup>>(
|
||||
'evaluation_point_groups',
|
||||
data,
|
||||
apiGroup, // 使用转换后的对象
|
||||
{ id },
|
||||
token
|
||||
);
|
||||
|
||||
|
||||
if (response.error) {
|
||||
return { error: response.error, status: response.status };
|
||||
}
|
||||
|
||||
|
||||
// 使用辅助函数提取数据
|
||||
const extractedData = extractApiData<RuleGroup>(response.data);
|
||||
|
||||
|
||||
if (!extractedData) {
|
||||
return { error: '更新成功但未返回数据' };
|
||||
}
|
||||
|
||||
|
||||
return { data: extractedData };
|
||||
} catch (error) {
|
||||
console.error('更新评查点分组失败:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '更新评查点分组失败'
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '更新评查点分组失败'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user