Skip to content

Commit

Permalink
link account to gliederung
Browse files Browse the repository at this point in the history
  • Loading branch information
axelrindle committed Sep 8, 2024
1 parent 93300c2 commit f0aa0a3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 24 deletions.
14 changes: 3 additions & 11 deletions api/email/account-activated.mjml
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
{{#> layout }}

<mj-text font-size="16px" line-height="1.5">
Dein <b>brahmsee.digital</b> Account wurde aktiviert. Du kannst dich jetzt anmelden.
Dein <b>brahmsee.digital</b> Account wurde bestätigt.
Bevor du dich anmelden kannst, muss dein Account noch durch einen Administrator
aktiviert werden.
</mj-text>

<mj-button
align="left"
background-color="#16a34a"
border-radius="8px"
font-size="16px"
href="{{ config 'clientUrl' }}/login"
>
Zur Anmeldung
</mj-button>

{{/layout}}
12 changes: 12 additions & 0 deletions api/email/account-status-changed.mjml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@
Der Status deines <b>brahmsee.digital</b> Account wurde auf <b>{{ status }}</b> geändert.
</mj-text>

{{#if isActive }}
<mj-button
align="left"
background-color="#16a34a"
border-radius="8px"
font-size="16px"
href="{{ config 'clientUrl' }}/login"
>
Zur Anmeldung
</mj-button>
{{/if}}

{{/layout}}
5 changes: 4 additions & 1 deletion api/src/scripts/createAccount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { input, password as passwordInput, select } from '@inquirer/prompts'
import { Role } from '@prisma/client'

import { getEnumOptions, roleMapping } from '../enumMappings'
import prisma from '../prisma'
Expand Down Expand Up @@ -31,14 +32,16 @@ async function createUser() {
})
}

const gliederungId = await selectGliederung()
const accountData = await getAccountCreateData({
email: email,
firstname: firstname,
lastname: lastname,
password: password,
roleId: roleId,
isActiv: true,
adminInGliederungId: roleId === 'GLIEDERUNG_ADMIN' ? await selectGliederung() : undefined,
gliederungId,
adminInGliederungId: roleId === Role.GLIEDERUNG_ADMIN ? gliederungId : undefined,
birthday: new Date(),
gender: 'FEMALE',
})
Expand Down
7 changes: 4 additions & 3 deletions api/src/services/account/accountGliederungAdminCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ZAccountGliederungAdminCreateInput = z.strictObject({
birthday: z.date(),
email: z.string().email().optional(), // email is required, because oauth login does not have an email
password: z.string().optional(), // optional, because oauth login does not have a password
adminInGliederungId: z.number().int(),
gliederungId: z.number().int(),
jwtOAuthToken: z.string().optional(), // optional, becaus normal registration does not have a jwtOAuthToken
}),
})
Expand Down Expand Up @@ -57,7 +57,8 @@ export const accountGliederungAdminCreateProcedure = defineProcedure({
gender: options.input.data.gender,
roleId: 'GLIEDERUNG_ADMIN',
isActiv: false,
adminInGliederungId: options.input.data.adminInGliederungId,
gliederungId: options.input.data.gliederungId,
adminInGliederungId: options.input.data.gliederungId,
})
const res = await prisma.account.create({
data: {
Expand All @@ -69,7 +70,7 @@ export const accountGliederungAdminCreateProcedure = defineProcedure({
},
})

await sendMailConfirmEmailRequest(accountData.email, accountData.activationToken)
await sendMailConfirmEmailRequest(accountData.email, accountData.activationToken!)

return res
},
Expand Down
4 changes: 4 additions & 0 deletions api/src/services/account/accountVerwaltungCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export const accountVerwaltungCreateProcedure = defineProcedure({
}),
async handler(options) {
const accountData = await getAccountCreateData(options.input.data)
if (typeof accountData.activationToken !== 'string') {
throw new Error('no activation token found!')
}

const res = prisma.account.create({
data: accountData,
select: {
Expand Down
1 change: 1 addition & 0 deletions api/src/services/account/accountVerwaltungPatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const accountVerwaltungPatchProcedure = defineProcedure({
name: `${account.person.firstname} ${account.person.lastname}`,
gliederung: account.person.gliederung!.name,
status: AccountStatusMapping[account.status].human,
isActive: account.status === AccountStatus.AKTIV,
},
})
}
Expand Down
12 changes: 9 additions & 3 deletions api/src/services/account/schema/account.schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Gender, Role, AccountStatus } from '@prisma/client'
import { Gender, Role, AccountStatus, Prisma, GliederungAccountRole } from '@prisma/client'
import { v4 as uuidv4 } from 'uuid'
import { z } from 'zod'

Expand All @@ -14,6 +14,7 @@ export const accountSchema = z.strictObject({
roleId: z.nativeEnum(Role),
isActiv: z.boolean().optional(),
status: z.nativeEnum(AccountStatus).optional(),
gliederungId: z.number().int(),
adminInGliederungId: z.number().int().optional(),
activationToken: z.string().optional(),
passwordResetToken: z.string().optional(),
Expand All @@ -27,7 +28,7 @@ const ZGetAccountCreateDataSchema = accountSchema.extend({

type TGetAccountCreateDataSchema = z.infer<typeof ZGetAccountCreateDataSchema>

export async function getAccountCreateData(data: TGetAccountCreateDataSchema) {
export async function getAccountCreateData(data: TGetAccountCreateDataSchema): Promise<Prisma.AccountCreateInput> {
return {
email: data.email,
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
Expand All @@ -41,6 +42,11 @@ export async function getAccountCreateData(data: TGetAccountCreateDataSchema) {
birthday: data.birthday,
email: data.email,
telefon: '',
gliederung: {
connect: {
id: data.gliederungId,
},
},
},
},
activatedAt: data.isActiv ? new Date() : null,
Expand All @@ -49,7 +55,7 @@ export async function getAccountCreateData(data: TGetAccountCreateDataSchema) {
? {
create: {
gliederungId: data.adminInGliederungId,
role: 'DELEGATIONSLEITER' as const,
role: GliederungAccountRole.DELEGATIONSLEITER,
},
}
: undefined,
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/views/Registrierung/GliederungRegistrierung.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import BasicPassword from '@/components/BasicInputs/BasicPassword.vue'
import BasicTypeahead from '@/components/BasicInputs/BasicTypeahead.vue'
import Stammdaten, { type IStammdaten } from '@/components/forms/anmeldung/Stammdaten.vue'
import Button from '@/components/UIComponents/Button.vue'
import type { RouterInput, RouterOutput, TAccountSchema } from '@codeanker/api'
import type { RouterInput, RouterOutput } from '@codeanker/api'
import { ValidateForm } from '@codeanker/validation'
const stammdatenForm = ref<IStammdaten>({
Expand Down Expand Up @@ -46,9 +46,7 @@ async function watiForOAuth(): Promise<string> {
})
}
type TAccountData = Partial<TAccountSchema> & {
jwtOAuthToken?: string
}
type TAccountData = RouterInput['account']['gliederungAdminCreate']['data']
async function registerGliederung() {
try {
Expand All @@ -58,10 +56,10 @@ async function registerGliederung() {
firstname: stammdatenForm.value.firstname,
lastname: stammdatenForm.value.lastname,
gender: stammdatenForm.value.gender,
birthday: stammdatenForm.value.birthday ? new Date(stammdatenForm.value.birthday) : undefined,
birthday: stammdatenForm.value.birthday ?? new Date(),
email: registrationForm.value.email,
password: registrationForm.value.password,
adminInGliederungId: registrationForm.value.gliederung?.id,
gliederungId: registrationForm.value.gliederung!.id,
}
if (oauthRegistration.value) {
Expand Down

0 comments on commit f0aa0a3

Please sign in to comment.