MCPcopy
hub / github.com/superplanehq/superplane / CreateOrganizationInTransaction

Function CreateOrganizationInTransaction

pkg/models/organization.go:177–207  ·  view source on GitHub ↗
(tx *gorm.DB, name, description string)

Source from the content-addressed store, hash-verified

175}
176
177func 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
209func SoftDeleteOrganization(id string) error {
210 return SoftDeleteOrganizationInTransaction(database.Conn(), id)

Callers 5

createOrganizationMethod · 0.92
setupOwnerMethod · 0.92
SetupWithOptionsFunction · 0.92
CreateOrganizationFunction · 0.92
CreateOrganizationFunction · 0.85

Calls 3

CreateMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected