Skip to content

Commit 629404e

Browse files
authored
Merge pull request #60 from appcircleio/feature/be-6105
#BE-6105 add create-sub organization feature.
2 parents 902c33e + c9964ef commit 629404e

5 files changed

Lines changed: 61 additions & 0 deletions

File tree

docs/organization/create-sub.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# `appcircle organization create-sub`
2+
3+
Create a new sub-organization under the current organization.
4+
5+
```plaintext
6+
appcircle organization create-sub [options]
7+
```
8+
9+
## Options
10+
11+
```plaintext
12+
--name <string> Name of the sub-organization
13+
```
14+
## Options inherited from parent commands
15+
16+
```plaintext
17+
--help Show help for command
18+
```

docs/organization/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ appcircle organization [command] [options]
1515
## Subcommands
1616

1717
- [`view`](view.md)
18+
- [`create-sub`](create-sub.md)
1819
- [`user`](user/index.md)
1920
- [`role`](role/index.md)
2021

src/core/command-runner.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import {
112112
commitEnterpriseFileUpload,
113113
updateTestingDistributionReleaseNotes,
114114
getLatestAppVersionId,
115+
createSubOrganization
115116
} from '../services';
116117
import { commandWriter, configWriter } from './writer';
117118
import { trustAppcircleCertificate } from '../security/trust-url-certificate';
@@ -259,6 +260,16 @@ const handleOrganizationCommand = async (command: ProgramCommand, params: any) =
259260
fullCommandName: command.fullCommandName,
260261
data: userInfo.roles,
261262
});
263+
} else if (command.fullCommandName === `${PROGRAM_NAME}-organization-create-sub`) {
264+
const spinner = createOra('Creating sub-organization...').start();
265+
try {
266+
const response = await createSubOrganization({ name: params.name });
267+
const successMessage = `${params.name} sub organization created successfully!`;
268+
spinner.succeed(successMessage);
269+
} catch (error: any) {
270+
const errorMessage = error.response?.data?.message || error.message || 'Failed to create sub-organization';
271+
spinner.fail(`Error: ${errorMessage}`);
272+
}
262273
} else {
263274
const beutufiyCommandName = command.fullCommandName.split('-').join(' ');
264275
console.error(`"${beutufiyCommandName} ..." command not found \nRun "${beutufiyCommandName} --help" for more information`);

src/core/commands.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,18 @@ export const Commands: CommandType[] = [
17131713
required: false,
17141714
}],
17151715
},
1716+
{
1717+
command: 'create-sub',
1718+
description: 'Create a sub-organization',
1719+
longDescription: 'Create a new sub-organization under the current organization.',
1720+
params: [{
1721+
name: 'name',
1722+
description: 'Name of the sub-organization',
1723+
type: CommandParameterTypes.STRING,
1724+
valueType: 'string',
1725+
required: true,
1726+
}],
1727+
},
17161728
{
17171729
command: 'user',
17181730
description: 'User management',

src/services/organization.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,23 @@ export const getOrganizationUserinfo = async (options: OptionsType<{ organizatio
208208
}
209209

210210
return user;
211+
};
212+
213+
/**
214+
* Creates a sub-organization under the current organization.
215+
*
216+
* @param {OptionsType<{ name: string }>} options - Object containing name of the sub-organization to be created.
217+
* @return {Promise<any>} The data returned from the creation response.
218+
*/
219+
export const createSubOrganization = async (options: OptionsType<{ name: string }>) => {
220+
const response = await appcircleApi.post(
221+
`identity/v1/organizations/current/sub-organizations`,
222+
{
223+
name: options.name
224+
},
225+
{
226+
headers: getHeaders(),
227+
}
228+
);
229+
return response.data;
211230
};

0 commit comments

Comments
 (0)