fix: 审批接口自动补全缺失的approval记录
旧ticket可能没有关联approval记录(创建时代码不同), 导致approve/reject报400 No pending approval。 现在admin/dba角色会自动创建approval记录再审批。
This commit is contained in:
1 parent
efd22b9c15
commit
86eea25031
1 file changed
+20
-3
@@ -255,11 +255,28 @@ func ApproveTicket(c *gin.Context) {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
// Update approval record
|
||||
// Update approval record — auto-create if missing (legacy tickets)
|
||||
var approval model.TicketApproval
|
||||
if err := model.DB.Where("ticket_id = ? AND approver_id = ? AND action IS NULL", id, userID).First(&approval).Error; err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"detail": "No pending approval for you"})
|
||||
return
|
||||
// No approval record — check if user is authorized to review
|
||||
_, userRole, _ := middleware.GetCurrentUser(c)
|
||||
if userRole == "admin" || userRole == "dba" {
|
||||
stepName := "审核"
|
||||
stepType := "audit"
|
||||
approverRole := userRole
|
||||
approval = model.TicketApproval{
|
||||
TicketID: ticket.ID,
|
||||
StepNumber: 1,
|
||||
StepName: &stepName,
|
||||
StepType: &stepType,
|
||||
ApproverID: &userID,
|
||||
ApproverRole: &approverRole,
|
||||
}
|
||||
model.DB.Create(&approval)
|
||||
} else {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"detail": "No pending approval for you"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
approval.Action = &input.Action
|
||||
|
||||
Reference in new issue
Block a user