(updateAlert dto.AlertCreate, operator string)
| 698 | } |
| 699 | |
| 700 | func (a AlertService) ExternalUpdateAlert(updateAlert dto.AlertCreate, operator string) error { |
| 701 | if err := a.validateCommunityAlertMethod(updateAlert.Method); err != nil { |
| 702 | return err |
| 703 | } |
| 704 | upMap := make(map[string]interface{}) |
| 705 | var newStatus string |
| 706 | if updateAlert.SendCount == 0 { |
| 707 | newStatus = constant.AlertDisable |
| 708 | } else { |
| 709 | newStatus = constant.AlertEnable |
| 710 | upMap["send_count"] = updateAlert.SendCount |
| 711 | if updateAlert.Method != "" { |
| 712 | upMap["method"] = updateAlert.Method |
| 713 | } |
| 714 | } |
| 715 | upMap["status"] = newStatus |
| 716 | |
| 717 | alertInfo, _ := alertRepo.Get( |
| 718 | alertRepo.WithByType(updateAlert.Type), |
| 719 | alertRepo.WithByProject(updateAlert.Project), |
| 720 | ) |
| 721 | |
| 722 | if alertInfo.ID > 0 { |
| 723 | shouldUpdate := false |
| 724 | |
| 725 | if alertInfo.Status != newStatus { |
| 726 | shouldUpdate = true |
| 727 | } |
| 728 | if val, ok := upMap["send_count"]; ok && val != alertInfo.SendCount { |
| 729 | shouldUpdate = true |
| 730 | } |
| 731 | if val, ok := upMap["method"]; ok && val != "" && val != alertInfo.Method { |
| 732 | shouldUpdate = true |
| 733 | } |
| 734 | |
| 735 | if shouldUpdate { |
| 736 | if err := alertRepo.Update( |
| 737 | upMap, |
| 738 | alertRepo.WithByProject(updateAlert.Project), |
| 739 | alertRepo.WithByType(updateAlert.Type), |
| 740 | ); err != nil { |
| 741 | return err |
| 742 | } |
| 743 | } |
| 744 | } else { |
| 745 | if updateAlert.Method != "" && updateAlert.Title != "" { |
| 746 | updateAlert.Status = newStatus |
| 747 | if err := a.CreateAlert(updateAlert, operator); err != nil { |
| 748 | return err |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | return nil |
| 754 | } |
nothing calls this directly
no test coverage detected