fix: 修复评查点分组的结果保存异常

This commit is contained in:
2025-11-03 09:47:46 +08:00
parent 054fc4f697
commit 34cba4a34f
+29 -2
View File
@@ -516,10 +516,37 @@ 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}> { export async function updateRuleGroup(id: string, data: RuleGroupCreateUpdateDto, token?: string): Promise<{data: RuleGroup; error?: never} | {data?: never; error: string; status?: number}> {
try { 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参数 // 使用新的filters参数
const response = await postgrestPut<ApiResponse<RuleGroup> | RuleGroup, RuleGroupCreateUpdateDto>( const response = await postgrestPut<ApiResponse<RuleGroup> | RuleGroup, Partial<ApiRuleGroup>>(
'evaluation_point_groups', 'evaluation_point_groups',
data, apiGroup, // 使用转换后的对象
{ id }, { id },
token token
); );