(_ context.Context, tx *gorm.DB, id string, preload ...string)
| 268 | } |
| 269 | |
| 270 | func (s *sqlDatabase) getEnterpriseByID(_ context.Context, tx *gorm.DB, id string, preload ...string) (Enterprise, error) { |
| 271 | u, err := uuid.Parse(id) |
| 272 | if err != nil { |
| 273 | return Enterprise{}, fmt.Errorf("error parsing id: %w", runnerErrors.ErrBadRequest) |
| 274 | } |
| 275 | var enterprise Enterprise |
| 276 | |
| 277 | q := tx |
| 278 | if len(preload) > 0 { |
| 279 | for _, field := range preload { |
| 280 | q = q.Preload(field) |
| 281 | } |
| 282 | } |
| 283 | q = q.Where("id = ?", u).First(&enterprise) |
| 284 | |
| 285 | if q.Error != nil { |
| 286 | if errors.Is(q.Error, gorm.ErrRecordNotFound) { |
| 287 | return Enterprise{}, runnerErrors.ErrNotFound |
| 288 | } |
| 289 | return Enterprise{}, fmt.Errorf("error fetching enterprise from database: %w", q.Error) |
| 290 | } |
| 291 | return enterprise, nil |
| 292 | } |
no outgoing calls
no test coverage detected