MCPcopy Create free account
hub / github.com/linuxfoundation/crowd.dev / create

Method create

backend/src/services/tenantService.ts:166–314  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

164 }
165
166 async create(data) {
167 const transaction = await SequelizeRepository.createTransaction(this.options)
168
169 try {
170 if (TENANT_MODE === TenantMode.SINGLE) {
171 const count = await TenantRepository.count(null, {
172 ...this.options,
173 transaction,
174 })
175
176 if (count > 0) {
177 throw new Error400(this.options.language, 'tenant.exists')
178 }
179 }
180
181 if (data.integrationsRequired) {
182 // Convert all to lowercase
183 data.integrationsRequired = data.integrationsRequired.map((item) => item.toLowerCase())
184 }
185
186 const record = await TenantRepository.create(data, {
187 ...this.options,
188 transaction,
189 })
190
191 const segment = await new SegmentService({
192 ...this.options,
193 currentTenant: record,
194 transaction,
195 } as IServiceOptions).createProjectGroup({
196 name: data.name,
197 url: data.url,
198 slug: data.url || (await TenantRepository.generateTenantUrl(data.name, this.options)),
199 status: SegmentStatus.ACTIVE,
200 } as SegmentData)
201
202 this.options.currentSegments = [(segment as any).projects[0].subprojects[0]]
203
204 await SettingsService.findOrCreateDefault({
205 ...this.options,
206 currentTenant: record,
207 transaction,
208 })
209
210 const memberAttributeSettingsService = new MemberAttributeSettingsService({
211 ...this.options,
212 currentTenant: record,
213 })
214
215 // create default member attribute settings
216 await memberAttributeSettingsService.createPredefined(DEFAULT_MEMBER_ATTRIBUTES, transaction)
217
218 await TenantUserRepository.create(record, this.options.currentUser, [Roles.values.admin], {
219 ...this.options,
220 transaction,
221 })
222
223 // create default microservices for the tenant

Callers 3

importMethod · 0.95
createOrJoinDefaultMethod · 0.45

Calls 10

createPredefinedMethod · 0.95
createTransactionMethod · 0.80
createProjectGroupMethod · 0.80
generateTenantUrlMethod · 0.80
createSuggestedTasksMethod · 0.80
commitTransactionMethod · 0.80
rollbackTransactionMethod · 0.80
countMethod · 0.45
findOrCreateDefaultMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected