()
| 18 | } |
| 19 | |
| 20 | export async function deleteOrganization() { |
| 21 | console.log(chalk.red('\n🗑️ Delete Organization\n')); |
| 22 | console.log( |
| 23 | chalk.yellow( |
| 24 | '⚠️ WARNING: This will permanently delete the organization and all its data!\n', |
| 25 | ), |
| 26 | ); |
| 27 | console.log('Loading organizations...\n'); |
| 28 | |
| 29 | const organizations = await db.organization.findMany({ |
| 30 | include: { |
| 31 | projects: true, |
| 32 | members: { |
| 33 | include: { |
| 34 | user: true, |
| 35 | }, |
| 36 | }, |
| 37 | }, |
| 38 | orderBy: { |
| 39 | name: 'asc', |
| 40 | }, |
| 41 | }); |
| 42 | |
| 43 | if (organizations.length === 0) { |
| 44 | console.log(chalk.red('No organizations found.')); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | const searchItems: OrgSearchItem[] = organizations.map((org) => ({ |
| 49 | id: org.id, |
| 50 | name: org.name, |
| 51 | displayText: `${org.name} ${chalk.gray(`(${org.id})`)} ${chalk.cyan(`- ${org.projects.length} projects, ${org.members.length} members`)}`, |
| 52 | })); |
| 53 | |
| 54 | const searchFunction = async (_answers: unknown, input = '') => { |
| 55 | const fuzzyResult = fuzzy.filter(input, searchItems, { |
| 56 | extract: (item: OrgSearchItem) => `${item.name} ${item.id}`, |
| 57 | }); |
| 58 | |
| 59 | return fuzzyResult.map((result: fuzzy.FilterResult<OrgSearchItem>) => ({ |
| 60 | name: result.original.displayText, |
| 61 | value: result.original, |
| 62 | })); |
| 63 | }; |
| 64 | |
| 65 | const { selectedOrg } = (await inquirer.prompt([ |
| 66 | { |
| 67 | type: 'autocomplete', |
| 68 | name: 'selectedOrg', |
| 69 | message: 'Search for an organization to delete:', |
| 70 | source: searchFunction, |
| 71 | pageSize: 15, |
| 72 | }, |
| 73 | ])) as { selectedOrg: OrgSearchItem }; |
| 74 | |
| 75 | // Fetch full organization details |
| 76 | const organization = await db.organization.findUnique({ |
| 77 | where: { |
no test coverage detected