* NTP-24894 | Text change in slack modal. * NTP-24894 | Adding more constant teamTypes. * NTP-24894 | Added functions to allow for teamType update. * NTP-24894 | Added validation in addTeamRequest. * NTP-24894 | Comment resolution and new functions (#477) * NTP-24894 | Added filter on Reporting teams. * NTP-24894 | Added new function for all teams fetch in team service. * NTP-24894 | sending all teams in response for slack modal. * NTP-24894 | Added tests for UpdateTeam flow. * NTP-24894 | Fixing logic and using util. * NTP-24894 | Using enum-map for teamType validation. * NTP-24894 | Variable name change. * NTP-24894 | Adding teamType to TeamDTOs when fetching using productid. * NTP-24894 | Revisions in function for team population. * NTP-24894 | Removed unneeded function. * NTP-24894 | Removed unneeded interface of function * NTP-24894 | Updated test scripts. * NTP-24894 | Logic changes, modal text change. * NTP-24894 | Using ID for first occurence, updated tests. * NTP-40086 | Selective filtering based on Product. * NTP-40086 | Updated tests for incident_orch. * NTP-40086 | replaced with constants. * NTP-24894 | Moved functions to teamService. * NTP-40086 | added new function in repo for filtering during fetch. * NTP-40086 | Removed unused function. * NTP-40086 | added tests and removed interface of previously removed fuc. * NTP-40086 | Added direct filtering function during data fetch from repo. * NTP-40086 | Refactoring and adding more tests. * NTP-24894 | Text changed in incident summary. * NTP-40086 | Refactoring function. * NTP-40086 | Editting team service for unused functions. * NTP-40086 | Added new util function for generic intersection. * NTP-40086 | Text changed at multiple places. * NTP-40086 | Text change. * NTP-40086 | text change.
187 lines
5.8 KiB
Go
187 lines
5.8 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"github.com/google/uuid"
|
|
"github.com/spf13/viper"
|
|
service "houston/service/request"
|
|
"houston/service/request/incident"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func ValidatePage(pageSize, pageNumber string) (int64, int64, error) {
|
|
pageSizeInteger, err := strconv.ParseInt(pageSize, 0, 64)
|
|
if err != nil {
|
|
pageSizeInteger = 10
|
|
}
|
|
pageNumberInteger, err := strconv.ParseInt(pageNumber, 0, 64)
|
|
if err != nil {
|
|
pageNumberInteger = 0
|
|
}
|
|
|
|
if pageSizeInteger == 0 {
|
|
return 0, 0, errors.New("page size cannot be zero")
|
|
}
|
|
|
|
return pageSizeInteger, pageNumberInteger, nil
|
|
}
|
|
|
|
func ValidateUpdateIncidentRequest(request service.UpdateIncidentRequest, userEmail string) error {
|
|
if userEmail == "" {
|
|
return errors.New("user email header missing in update request")
|
|
}
|
|
if request.Id == 0 {
|
|
return errors.New("id should be present in update request")
|
|
}
|
|
if request.SeverityId == "" && request.Status == "" && request.TeamId == "" &&
|
|
request.MetaData == nil && request.ProductIDs == nil {
|
|
return errors.New("update request should contain at least one field to update")
|
|
}
|
|
|
|
if len(request.ProductIDs) > 0 && request.TeamId == "" {
|
|
return errors.New("responder team ID must be provided when product is being updated")
|
|
}
|
|
|
|
if request.MetaData != nil && (request.MetaData.CustomerId == uuid.Nil || request.MetaData.PhoneNumber == "" || request.MetaData.CrmTicketCreationTime == nil || request.MetaData.TicketId == "" || request.MetaData.TicketGroup == "" || request.MetaData.AgentName == "") {
|
|
return errors.New("metadata should contain customer id, phone number and crm ticket creation time")
|
|
}
|
|
if len(request.Justification) > 100 {
|
|
return errors.New("justification should not be more than 100 characters long")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func ValidateResolveIncidentRequest(request service.ResolveIncidentRequest) error {
|
|
if request.IncidentID == 0 {
|
|
return errors.New("Incident I.D should be present in resolve incident request")
|
|
}
|
|
|
|
if request.BusinessAffected == nil || len(request.BusinessAffected) == 0 {
|
|
return errors.New("Business affected should be present in resolve incident request")
|
|
}
|
|
|
|
if request.ContributingFactors == 0 {
|
|
return errors.New("Contributing Factors should be present in resolve incident request")
|
|
}
|
|
|
|
if request.RcaSummary == "" {
|
|
return errors.New("Rca Summary should be present in resolve incident request")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func ValidateCreateIncidentRequestV3(request incident.CreateIncidentRequestV3) error {
|
|
if request.Title == "" || request.Description == "" {
|
|
return errors.New("title and description should be present in create request")
|
|
}
|
|
descriptionMaxLength := viper.GetInt("create-incident.description.max-length")
|
|
titleMaxLength := viper.GetInt("create-incident.title.max-length")
|
|
if len(request.Description) > descriptionMaxLength {
|
|
return errors.New(fmt.Sprintf("description should not be more than %v characters long", descriptionMaxLength))
|
|
}
|
|
if len(request.Title) > titleMaxLength {
|
|
return errors.New(fmt.Sprintf("title should not be more than %v characters long", titleMaxLength))
|
|
}
|
|
if request.CreatedBy == "" {
|
|
return errors.New("created by should be present")
|
|
}
|
|
if request.ReportingTeamID == 0 {
|
|
return errors.New("business/function affected ID should be present")
|
|
}
|
|
if len(request.ProductIds) == 0 {
|
|
return errors.New("product I.Ds should be present")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ValidatePostRcaRequest(request service.PostRcaRequest) error {
|
|
if request.Status == StatusSuccess {
|
|
var successData service.SuccessData
|
|
err := json.Unmarshal(request.Data, &successData)
|
|
if err != nil {
|
|
return errors.New("Invalid success data")
|
|
}
|
|
|
|
if successData.RcaLink == "" {
|
|
return errors.New("Please provide RCA link on successful RCA generation")
|
|
}
|
|
} else if request.Status == StatusFailure {
|
|
var failureData service.FailureData
|
|
err := json.Unmarshal(request.Data, &failureData)
|
|
if err != nil {
|
|
return errors.New("Invalid failure data")
|
|
}
|
|
|
|
if failureData.Reason == "" {
|
|
return errors.New("Please provide failure reason for RCA generation failure")
|
|
}
|
|
} else {
|
|
return errors.New("rca generation status must be specified as 'SUCCESS' or 'FAILURE'")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func ValidateLinkJiraRequest(request service.LinkJiraRequest) error {
|
|
var errorMessage []string
|
|
if request.IncidentID == 0 {
|
|
errorMessage = append(errorMessage, "Enter a valid incident I.D.")
|
|
}
|
|
if request.JiraLink == "" {
|
|
errorMessage = append(errorMessage, "Jira links can not be empty")
|
|
}
|
|
if strings.HasPrefix(request.JiraLink, viper.GetString("navi.jira.base.url")) == false {
|
|
errorMessage = append(errorMessage, fmt.Sprintf("%s is not a valid Jira link", request.JiraLink))
|
|
}
|
|
if request.User == "" {
|
|
errorMessage = append(errorMessage, "Enter a valid navi email or slack ID for the linked_by field")
|
|
}
|
|
if errorMessage != nil {
|
|
return fmt.Errorf(strings.Join(errorMessage, ". "))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ValidateUpdateTeamRequest(request service.UpdateTeamRequest) error {
|
|
if request.Id == 0 {
|
|
return errors.New("id should be present in update request")
|
|
}
|
|
if request.WorkEmailIds == nil || len(request.WorkEmailIds) == 0 {
|
|
request.WorkEmailIds = []string{}
|
|
}
|
|
if request.SlackUserIds == nil || len(request.SlackUserIds) == 0 {
|
|
request.SlackUserIds = []string{}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ValidateUpdateSeverityRequest(request service.UpdateSeveritiesRequest) error {
|
|
for _, severity := range request.Severities {
|
|
if severity.Id == 0 {
|
|
return errors.New("id should be present to update severity")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ValidateIdParameter(id string) (uint, error) {
|
|
if id == "" {
|
|
return 0, errors.New("id parameter cannot be empty")
|
|
}
|
|
ID, err := strconv.Atoi(id)
|
|
if err != nil || ID < 0 {
|
|
return 0, errors.New("id parameter is invalid")
|
|
}
|
|
return uint(ID), nil
|
|
}
|
|
|
|
const (
|
|
StatusSuccess = "SUCCESS"
|
|
StatusFailure = "FAILURE"
|
|
)
|