feat(health): 积分规则查重 — 同租户同事件类型不可重复创建
- 新增迁移 m20260526_000163:points_rule (tenant_id, event_type) 部分唯一索引(排除软删除行) - 后端 create_rule 添加 event_type 查重,重复时返回 400 Validation 错误 - 前端 PointsRuleList 提取后端错误消息展示给用户
This commit is contained in:
@@ -59,6 +59,20 @@ pub async fn create_rule(
|
||||
operator_id: Option<Uuid>,
|
||||
req: CreatePointsRuleReq,
|
||||
) -> HealthResult<PointsRuleResp> {
|
||||
// 查重:同一租户下不允许重复的 event_type
|
||||
let existing = points_rule::Entity::find()
|
||||
.filter(points_rule::Column::TenantId.eq(tenant_id))
|
||||
.filter(points_rule::Column::EventType.eq(&req.event_type))
|
||||
.filter(points_rule::Column::DeletedAt.is_null())
|
||||
.one(&state.db)
|
||||
.await?;
|
||||
if existing.is_some() {
|
||||
return Err(HealthError::Validation(format!(
|
||||
"事件类型 '{}' 已存在规则,不可重复创建",
|
||||
req.event_type
|
||||
)));
|
||||
}
|
||||
|
||||
let now = Utc::now();
|
||||
let active = points_rule::ActiveModel {
|
||||
id: Set(Uuid::now_v7()),
|
||||
|
||||
Reference in New Issue
Block a user