(req dto.AlertConfigUpdate, operator string)
| 506 | } |
| 507 | |
| 508 | func (a AlertService) UpdateAlertConfig(req dto.AlertConfigUpdate, operator string) error { |
| 509 | if err := a.validateCommunityAlertConfigType(req.Type); err != nil { |
| 510 | return err |
| 511 | } |
| 512 | if err := a.checkAlertConfigDisplayNameUnique(req); err != nil { |
| 513 | return err |
| 514 | } |
| 515 | if err := a.checkAlertConfigSMSPhoneUnique(req); err != nil { |
| 516 | return err |
| 517 | } |
| 518 | if req.ID != 0 { |
| 519 | upMap := make(map[string]interface{}) |
| 520 | upMap["id"] = req.ID |
| 521 | upMap["type"] = req.Type |
| 522 | upMap["title"] = req.Title |
| 523 | upMap["status"] = req.Status |
| 524 | upMap["config"] = req.Config |
| 525 | upMap["update_user"] = operator |
| 526 | if err := alertRepo.UpdateAlertConfig(upMap, repo.WithByID(req.ID)); err != nil { |
| 527 | return err |
| 528 | } |
| 529 | } else { |
| 530 | var alertConfig model.AlertConfig |
| 531 | if err := copier.Copy(&alertConfig, &req); err != nil { |
| 532 | return buserr.WithErr("ErrStructTransform", err) |
| 533 | } |
| 534 | alertConfig.CreateUser = operator |
| 535 | alertConfig.UpdateUser = operator |
| 536 | if err := alertRepo.CreateAlertConfig(&alertConfig); err != nil { |
| 537 | return err |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | return nil |
| 542 | } |
| 543 | |
| 544 | func (a AlertService) checkAlertConfigSMSPhoneUnique(req dto.AlertConfigUpdate) error { |
| 545 | if req.Type != constant.SMSConfig { |
nothing calls this directly
no test coverage detected