From fdc33d5161d1233c2df1792dcd422f6fcc0476ec Mon Sep 17 00:00:00 2001 From: N3loDevelopment Date: Thu, 8 Oct 2026 05:57:20 +0200 Subject: [PATCH 1/6] fix: add diverse as separate gender option --- apps/api/src/types/enums/mappings/Gender.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/api/src/types/enums/mappings/Gender.ts b/apps/api/src/types/enums/mappings/Gender.ts index 8c3f12c8..8f42d12c 100644 --- a/apps/api/src/types/enums/mappings/Gender.ts +++ b/apps/api/src/types/enums/mappings/Gender.ts @@ -5,7 +5,8 @@ import { defineEnumMapping } from '../defineEnumMapping.js' export const GenderMapping = defineEnumMapping({ MALE: { human: 'Männlich' }, FEMALE: { human: 'Weiblich' }, - UNSPECIFIED: { human: 'Divers' }, + DIVERS: { human: 'Divers' }, + UNSPECIFIED: { human: 'Keine Angabe' }, }) export { type Gender } From 66b029e716749d344d0943ee39ac1d059a2a368f Mon Sep 17 00:00:00 2001 From: N3loDevelopment Date: Thu, 8 Oct 2026 05:58:22 +0200 Subject: [PATCH 2/6] fix: add diverse into prisma as gender --- apps/api/prisma/schema/Person.prisma | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/api/prisma/schema/Person.prisma b/apps/api/prisma/schema/Person.prisma index 93cd90e3..5f8407d0 100644 --- a/apps/api/prisma/schema/Person.prisma +++ b/apps/api/prisma/schema/Person.prisma @@ -3,6 +3,7 @@ enum Gender { MALE FEMALE + DIVERS UNSPECIFIED } From 41d050324fab8c0f3e4ef6bff6628b468772312b Mon Sep 17 00:00:00 2001 From: N3loDevelopment Date: Thu, 8 Oct 2026 06:15:42 +0200 Subject: [PATCH 3/6] fix(api): suppress Prisma debug logs during account prompts --- apps/api/src/prisma.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/api/src/prisma.ts b/apps/api/src/prisma.ts index eb948ee8..a4f781de 100644 --- a/apps/api/src/prisma.ts +++ b/apps/api/src/prisma.ts @@ -24,10 +24,25 @@ const prisma = new PrismaClient({ }, }) +let queryLoggingEnabled = config.loggingLevel === 'debug' + if (config.loggingLevel === 'debug') { prisma.$on('query', (e) => { - log.debug(e.query) + if (queryLoggingEnabled) { + log.debug(e.query) + } }) } +export async function withoutQueryLogging(callback: () => Promise): Promise { + const previousQueryLoggingEnabled = queryLoggingEnabled + queryLoggingEnabled = false + + try { + return await callback() + } finally { + queryLoggingEnabled = previousQueryLoggingEnabled + } +} + export default prisma From 42afb75fbdc97fbdfd2a91cba4ef7223ac01d1c1 Mon Sep 17 00:00:00 2001 From: N3loDevelopment Date: Thu, 8 Oct 2026 06:30:47 +0200 Subject: [PATCH 4/6] fix: persist DIVERS gender in database enum --- apps/api/prisma/migrations/20260201195324_init/migration.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/prisma/migrations/20260201195324_init/migration.sql b/apps/api/prisma/migrations/20260201195324_init/migration.sql index c4daf0a9..8aff7a80 100644 --- a/apps/api/prisma/migrations/20260201195324_init/migration.sql +++ b/apps/api/prisma/migrations/20260201195324_init/migration.sql @@ -26,7 +26,7 @@ CREATE TYPE "GliederungAccountRole" AS ENUM ('DELEGATIONSLEITER', 'BETREUER', 'T CREATE TYPE "MahlzeitType" AS ENUM ('FRUEHSTUECK', 'MITTAGESSEN', 'ABENDESSEN'); -- CreateEnum -CREATE TYPE "Gender" AS ENUM ('MALE', 'FEMALE', 'UNSPECIFIED'); +CREATE TYPE "Gender" AS ENUM ('MALE', 'FEMALE', 'DIVERS', 'UNSPECIFIED'); -- CreateEnum CREATE TYPE "Essgewohnheit" AS ENUM ('OMNIVOR', 'VEGETARISCH', 'VEGAN'); From 2c742ce56509099901b1648d66b52dd3ef52a65e Mon Sep 17 00:00:00 2001 From: N3loDevelopment Date: Thu, 8 Oct 2026 06:31:47 +0200 Subject: [PATCH 5/6] fix/add: prompt for gender and birthday when creating accounts --- apps/api/src/scripts/createAccount.ts | 87 ++++++++++++++++++++------- 1 file changed, 66 insertions(+), 21 deletions(-) diff --git a/apps/api/src/scripts/createAccount.ts b/apps/api/src/scripts/createAccount.ts index 3d79f170..b75dc4ba 100644 --- a/apps/api/src/scripts/createAccount.ts +++ b/apps/api/src/scripts/createAccount.ts @@ -1,28 +1,54 @@ import { input, password as passwordInput, select, search } from '@inquirer/prompts' import { Role } from '@prisma/client' -import prisma from '../prisma.js' +import prisma, { withoutQueryLogging } from '../prisma.js' import { getAccountCreateData } from '../services/account/schema/account.schema.js' import logActivity from '../util/activity.js' -import { getEnumOptions, roleMapping } from '../client.js' +import { getEnumOptions, roleMapping, GenderMapping } from '../client.js' + +function parseBirthday(value: string): Date | undefined { + if (!/^\d{2}-\d{2}-\d{4}$/.test(value)) { + return undefined + } + + const day = Number(value.slice(0, 2)) + const month = Number(value.slice(3, 5)) + const year = Number(value.slice(6, 10)) + const birthday = new Date(Date.UTC(year, month - 1, day)) + + if ( + birthday.getUTCFullYear() !== year || + birthday.getUTCMonth() !== month - 1 || + birthday.getUTCDate() !== day + ) { + return undefined + } + + const today = new Date() + const todayAtMidnight = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate())) + if (birthday > todayAtMidnight) { + return undefined + } + + return birthday +} async function createUser() { const email = await input({ message: 'E-Mail' }) const firstname = await input({ message: 'Vorname' }) const lastname = await input({ message: 'Nachname' }) const password = await passwordInput({ message: 'Passwort' }) + const roleId = await select({ message: 'Rolle', - choices: getEnumOptions(roleMapping).map((option) => { - return { - name: option.label, - value: option.value, - } - }), + choices: getEnumOptions(roleMapping).map((option) => ({ + name: option.label, + value: option.value, + })), }) - async function selectGliederung(): Promise { - return await search({ + const gliederungId = await withoutQueryLogging(() => + search({ message: 'Deine Gliederung', source: async (term) => { const results = await prisma.gliederung.findMany({ @@ -40,20 +66,39 @@ async function createUser() { })) }, }) + ) + const birthdayInput = await input({ + message: 'Geburtsdatum (TT-MM-JJJJ)', + validate: (value) => + parseBirthday(value) ? true : 'Bitte ein gültiges Datum im Format TT-MM-JJJJ eingeben, das nicht in der Zukunft liegt.', + }) + const birthday = parseBirthday(birthdayInput) + if (!birthday) { + throw new Error('Ungültiges Geburtsdatum.') } - const gliederungId = await selectGliederung() + const gender = await select({ + message: 'Geschlecht', + choices: getEnumOptions(GenderMapping).map((option) => ({ + name: option.label, + value: option.value, + })), + }) + const accountData = await getAccountCreateData({ - email: email, - firstname: firstname, - lastname: lastname, - password: password, - roleId: roleId, + email, + firstname, + lastname, + password, + roleId, isActiv: true, gliederungId, - adminInGliederungId: roleId === Role.GLIEDERUNG_ADMIN ? gliederungId : undefined, - birthday: new Date(), - gender: 'FEMALE', + adminInGliederungId: + roleId === Role.GLIEDERUNG_ADMIN + ? gliederungId + : undefined, + birthday, + gender, }) const res = await prisma.account.create({ @@ -69,7 +114,7 @@ async function createUser() { await logActivity({ type: 'CREATE', - description: `account was created via CLI script`, + description: 'account was created via CLI script', subjectType: 'account', subjectId: res.id, }) @@ -78,4 +123,4 @@ async function createUser() { process.exit() } -await createUser() +await createUser() \ No newline at end of file From 1ae4c0e4c6cc209f8abe467c999005201fd37156 Mon Sep 17 00:00:00 2001 From: N3loDevelopment Date: Thu, 8 Oct 2026 06:52:58 +0200 Subject: [PATCH 6/6] fix: add DIVERS through a new migration --- apps/api/prisma/migrations/20260201195324_init/migration.sql | 2 +- .../migrations/20261008065000_add_divers_gender/migration.sql | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 apps/api/prisma/migrations/20261008065000_add_divers_gender/migration.sql diff --git a/apps/api/prisma/migrations/20260201195324_init/migration.sql b/apps/api/prisma/migrations/20260201195324_init/migration.sql index 8aff7a80..c4daf0a9 100644 --- a/apps/api/prisma/migrations/20260201195324_init/migration.sql +++ b/apps/api/prisma/migrations/20260201195324_init/migration.sql @@ -26,7 +26,7 @@ CREATE TYPE "GliederungAccountRole" AS ENUM ('DELEGATIONSLEITER', 'BETREUER', 'T CREATE TYPE "MahlzeitType" AS ENUM ('FRUEHSTUECK', 'MITTAGESSEN', 'ABENDESSEN'); -- CreateEnum -CREATE TYPE "Gender" AS ENUM ('MALE', 'FEMALE', 'DIVERS', 'UNSPECIFIED'); +CREATE TYPE "Gender" AS ENUM ('MALE', 'FEMALE', 'UNSPECIFIED'); -- CreateEnum CREATE TYPE "Essgewohnheit" AS ENUM ('OMNIVOR', 'VEGETARISCH', 'VEGAN'); diff --git a/apps/api/prisma/migrations/20261008065000_add_divers_gender/migration.sql b/apps/api/prisma/migrations/20261008065000_add_divers_gender/migration.sql new file mode 100644 index 00000000..c99b463a --- /dev/null +++ b/apps/api/prisma/migrations/20261008065000_add_divers_gender/migration.sql @@ -0,0 +1 @@ +ALTER TYPE "Gender" ADD VALUE IF NOT EXISTS 'DIVERS';