(tx *gorm.DB, name, description string)
| 175 | } |
| 176 | |
| 177 | func CreateOrganizationInTransaction(tx *gorm.DB, name, description string) (*Organization, error) { |
| 178 | now := time.Now() |
| 179 | organization := Organization{ |
| 180 | Name: name, |
| 181 | Description: description, |
| 182 | AllowedProviders: datatypes.JSONSlice[string]{ProviderGitHub}, |
| 183 | EnabledExperimentalFeatures: datatypes.JSONSlice[string]{}, |
| 184 | CreatedAt: &now, |
| 185 | UpdatedAt: &now, |
| 186 | } |
| 187 | |
| 188 | err := tx. |
| 189 | Clauses(clause.Returning{}). |
| 190 | Create(&organization). |
| 191 | Error |
| 192 | |
| 193 | if err == nil { |
| 194 | _, inviteErr := CreateInviteLinkInTransaction(tx, organization.ID) |
| 195 | if inviteErr != nil { |
| 196 | return nil, inviteErr |
| 197 | } |
| 198 | |
| 199 | return &organization, nil |
| 200 | } |
| 201 | |
| 202 | if strings.Contains(err.Error(), "duplicate key value violates unique constraint") { |
| 203 | return nil, ErrNameAlreadyUsed |
| 204 | } |
| 205 | |
| 206 | return nil, err |
| 207 | } |
| 208 | |
| 209 | func SoftDeleteOrganization(id string) error { |
| 210 | return SoftDeleteOrganizationInTransaction(database.Conn(), id) |
no test coverage detected