Skip to content

Commit

Permalink
feat: replace select with search in account creation
Browse files Browse the repository at this point in the history
  • Loading branch information
axelrindle committed Nov 24, 2024
1 parent 8ccd5c6 commit 0002c83
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 362 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"devDependencies": {
"@edge-runtime/types": "^2.2.8",
"@inquirer/prompts": "^2.3.1",
"@inquirer/prompts": "^7.1.0",
"@types/config": "^3.3.3",
"@types/http-status-codes": "^1.2.0",
"@types/koa": "^2.14.0",
Expand Down
23 changes: 17 additions & 6 deletions api/src/scripts/createAccount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { input, password as passwordInput, select } from '@inquirer/prompts'
import { input, password as passwordInput, select, search } from '@inquirer/prompts'
import { Role } from '@prisma/client'

import { getEnumOptions, roleMapping } from '../enumMappings'
Expand All @@ -23,12 +23,23 @@ async function createUser() {
})) as keyof typeof roleMapping

async function selectGliederung(): Promise<number> {
return await select({
return await search({
message: 'Deine Gliederung',
choices: (await prisma.gliederung.findMany()).map((v) => ({
name: v.name,
value: v.id,
})),
source: async (term) => {
const results = await prisma.gliederung.findMany({
where: {
name: {
contains: term,
mode: 'insensitive',
},
},
})

return results.map((v) => ({
name: v.name,
value: v.id,
}))
},
})
}

Expand Down
Loading

0 comments on commit 0002c83

Please sign in to comment.