generated from VLADIMIR/template
fix double applications
This commit is contained in:
@@ -78,7 +78,27 @@ func (s *Services) AddAction(ctx context.Context, req *proto.AddActionReq) (*pro
|
||||
if err := s.repository.AddActions(ctx, team.ID, actions); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, err.Error())
|
||||
}
|
||||
if err := s.repository.AddApplications(ctx, actions); err != nil {
|
||||
currentApplications, err := s.repository.GetApplications(ctx, team.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newApplications := make([]*models.Application, 0, len(actions))
|
||||
for _, action := range actions {
|
||||
for _, actionApplication := range action.Applications {
|
||||
f := false
|
||||
for _, currentApplication := range currentApplications {
|
||||
if currentApplication.Name == actionApplication.Name {
|
||||
f = true
|
||||
}
|
||||
}
|
||||
if !f {
|
||||
newApplications = append(newApplications, actionApplication)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.repository.AddApplications(ctx, team.ID, newApplications); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, err.Error())
|
||||
}
|
||||
addLog(team, "add action", actions)
|
||||
@@ -134,11 +154,11 @@ func (s *Services) GetTeams(ctx context.Context, _ *proto.GetTeamsReq) (*proto.G
|
||||
return nil, err
|
||||
}
|
||||
newTeam.SpendTime = int64(len(actions))
|
||||
applications, err := s.repository.GetApplications(ctx, team.ID, "NEW")
|
||||
currentApplications, err := s.repository.GetApplicationsByState(ctx, team.ID, "NEW")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newTeam.Applications = mapApplicationsToProtoApplications(applications)
|
||||
newTeam.Applications = mapApplicationsToProtoApplications(currentApplications)
|
||||
res = append(res, newTeam)
|
||||
}
|
||||
return &proto.GetTeamsRsp{Teams: res}, err
|
||||
|
||||
Reference in New Issue
Block a user