From e4e5f6dffb878fd1570d3b3831f1ba7d29ef7695 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Tue, 17 Sep 2024 16:44:39 +0200 Subject: [PATCH] member base data extend --- src/entity/communicationType.ts | 4 ++-- src/entity/member.ts | 2 ++ src/factory/admin/communication.ts | 4 ++-- src/factory/admin/member.ts | 25 +++++++++++++++++-------- src/service/memberService.ts | 9 +++++++++ src/service/membershipService.ts | 4 ++-- src/viewmodel/admin/member.models.ts | 3 +++ 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/entity/communicationType.ts b/src/entity/communicationType.ts index 6ff867d..c40d20b 100644 --- a/src/entity/communicationType.ts +++ b/src/entity/communicationType.ts @@ -15,10 +15,10 @@ export class communicationType { default: "", transformer: { from(value: string): Array { - return value.split(","); + return (value ?? "").split(","); }, to(value: Array): string { - return value.join(","); + return (value ?? []).join(","); }, }, }) diff --git a/src/entity/member.ts b/src/entity/member.ts index a6e454a..d2be9b0 100644 --- a/src/entity/member.ts +++ b/src/entity/member.ts @@ -5,6 +5,7 @@ import { memberAwards } from "./memberAwards"; import { memberQualifications } from "./memberQualifications"; import { memberExecutivePositions } from "./memberExecutivePositions"; import { communication } from "./communication"; +import { CommunicationViewModel } from "../viewmodel/admin/communication.models"; @Entity() export class member { @@ -63,4 +64,5 @@ export class member { firstMembershipEntry?: membership; lastMembershipEntry?: membership; + preferredCommunication?: Array; } diff --git a/src/factory/admin/communication.ts b/src/factory/admin/communication.ts index bc4ac2b..1333515 100644 --- a/src/factory/admin/communication.ts +++ b/src/factory/admin/communication.ts @@ -8,7 +8,7 @@ export default abstract class CommunicationFactory { * @param {communication} record * @returns {CommunicationViewModel} */ - public static mapToSingle(record: communication): CommunicationViewModel { + public static mapToSingle(record: communication, isMain: boolean = false): CommunicationViewModel { return { id: record.id, preferred: record.preferred, @@ -19,7 +19,7 @@ export default abstract class CommunicationFactory { streetNumber: record.streetNumber, streetNumberAddition: record.streetNumberAddition, type: CommunicationTypeFactory.mapToSingle(record.type), - isNewsletterMain: record.member.sendNewsletter?.id == record.id, + isNewsletterMain: isMain ? isMain : record?.member?.sendNewsletter?.id == record.id, }; } diff --git a/src/factory/admin/member.ts b/src/factory/admin/member.ts index 126b530..0745d10 100644 --- a/src/factory/admin/member.ts +++ b/src/factory/admin/member.ts @@ -1,5 +1,6 @@ import { member } from "../../entity/member"; import { MemberViewModel } from "../../viewmodel/admin/member.models"; +import CommunicationFactory from "./communication"; import MembershipFactory from "./membership"; export default abstract class MemberFactory { @@ -10,14 +11,22 @@ export default abstract class MemberFactory { */ public static mapToSingle(record: member): MemberViewModel { return { - id: record.id, - salutation: record.salutation, - firstname: record.firstname, - lastname: record.lastname, - nameaffix: record.nameaffix, - birthdate: record.birthdate, - firstMembershipEntry: MembershipFactory.mapToSingle(record.firstMembershipEntry), - lastMembershipEntry: MembershipFactory.mapToSingle(record.lastMembershipEntry), + id: record?.id, + salutation: record?.salutation, + firstname: record?.firstname, + lastname: record?.lastname, + nameaffix: record?.nameaffix, + birthdate: record?.birthdate, + firstMembershipEntry: record?.firstMembershipEntry + ? MembershipFactory.mapToSingle(record.firstMembershipEntry) + : null, + lastMembershipEntry: record?.lastMembershipEntry + ? MembershipFactory.mapToSingle(record.lastMembershipEntry) + : null, + sendNewsletter: record?.sendNewsletter ? CommunicationFactory.mapToSingle(record.sendNewsletter, true) : null, + preferredCommunication: record?.preferredCommunication + ? CommunicationFactory.mapToBase(record.preferredCommunication) + : null, }; } diff --git a/src/service/memberService.ts b/src/service/memberService.ts index ea0b311..842ef98 100644 --- a/src/service/memberService.ts +++ b/src/service/memberService.ts @@ -26,6 +26,15 @@ export default abstract class MemberService { ) .leftJoinAndSelect("membership_first.status", "status_first") .leftJoinAndSelect("membership_last.status", "status_last") + .leftJoinAndSelect("member.sendNewsletter", "communication") + .leftJoinAndSelect("communication.type", "communicationtype") + .leftJoinAndMapMany( + "member.preferredCommunication", + "member.communications", + "preferredCommunication", + "preferredCommunication.preferred = TRUE" + ) + .leftJoinAndSelect("preferredCommunication.type", "communicationtype_preferred") .offset(offset) .limit(count) .orderBy("member.lastname") diff --git a/src/service/membershipService.ts b/src/service/membershipService.ts index 0debf30..caa4273 100644 --- a/src/service/membershipService.ts +++ b/src/service/membershipService.ts @@ -12,7 +12,7 @@ export default abstract class MembershipService { return await dataSource .getRepository(membership) .createQueryBuilder("membership") - .leftJoinAndSelect("membership.membership", "membership") + .leftJoinAndSelect("membership.status", "membershipStatus") .where("membership.memberId = :memberId", { memberId: memberId }) .getMany() .then((res) => { @@ -33,7 +33,7 @@ export default abstract class MembershipService { return await dataSource .getRepository(membership) .createQueryBuilder("membership") - .leftJoinAndSelect("membership.membership", "membership") + .leftJoinAndSelect("membership.status", "membershipStatus") .where("membership.memberId = :memberId", { memberId: memberId }) .andWhere("membership.id = :recordId", { recordId: recordId }) .getOneOrFail() diff --git a/src/viewmodel/admin/member.models.ts b/src/viewmodel/admin/member.models.ts index 33be015..5772ff5 100644 --- a/src/viewmodel/admin/member.models.ts +++ b/src/viewmodel/admin/member.models.ts @@ -1,4 +1,5 @@ import { Salutation } from "../../enums/salutation"; +import { CommunicationViewModel } from "./communication.models"; import { MembershipViewModel } from "./membership.models"; export interface MemberViewModel { @@ -10,4 +11,6 @@ export interface MemberViewModel { birthdate: Date; firstMembershipEntry?: MembershipViewModel; lastMembershipEntry?: MembershipViewModel; + sendNewsletter?: CommunicationViewModel; + preferredCommunication?: Array; }