member base data extend

This commit is contained in:
Julian Krauser 2024-09-17 16:44:39 +02:00
parent 80b1b5cf62
commit e4e5f6dffb
7 changed files with 37 additions and 14 deletions

View file

@ -15,10 +15,10 @@ export class communicationType {
default: "", default: "",
transformer: { transformer: {
from(value: string): Array<string> { from(value: string): Array<string> {
return value.split(","); return (value ?? "").split(",");
}, },
to(value: Array<string>): string { to(value: Array<string>): string {
return value.join(","); return (value ?? []).join(",");
}, },
}, },
}) })

View file

@ -5,6 +5,7 @@ import { memberAwards } from "./memberAwards";
import { memberQualifications } from "./memberQualifications"; import { memberQualifications } from "./memberQualifications";
import { memberExecutivePositions } from "./memberExecutivePositions"; import { memberExecutivePositions } from "./memberExecutivePositions";
import { communication } from "./communication"; import { communication } from "./communication";
import { CommunicationViewModel } from "../viewmodel/admin/communication.models";
@Entity() @Entity()
export class member { export class member {
@ -63,4 +64,5 @@ export class member {
firstMembershipEntry?: membership; firstMembershipEntry?: membership;
lastMembershipEntry?: membership; lastMembershipEntry?: membership;
preferredCommunication?: Array<communication>;
} }

View file

@ -8,7 +8,7 @@ export default abstract class CommunicationFactory {
* @param {communication} record * @param {communication} record
* @returns {CommunicationViewModel} * @returns {CommunicationViewModel}
*/ */
public static mapToSingle(record: communication): CommunicationViewModel { public static mapToSingle(record: communication, isMain: boolean = false): CommunicationViewModel {
return { return {
id: record.id, id: record.id,
preferred: record.preferred, preferred: record.preferred,
@ -19,7 +19,7 @@ export default abstract class CommunicationFactory {
streetNumber: record.streetNumber, streetNumber: record.streetNumber,
streetNumberAddition: record.streetNumberAddition, streetNumberAddition: record.streetNumberAddition,
type: CommunicationTypeFactory.mapToSingle(record.type), type: CommunicationTypeFactory.mapToSingle(record.type),
isNewsletterMain: record.member.sendNewsletter?.id == record.id, isNewsletterMain: isMain ? isMain : record?.member?.sendNewsletter?.id == record.id,
}; };
} }

View file

@ -1,5 +1,6 @@
import { member } from "../../entity/member"; import { member } from "../../entity/member";
import { MemberViewModel } from "../../viewmodel/admin/member.models"; import { MemberViewModel } from "../../viewmodel/admin/member.models";
import CommunicationFactory from "./communication";
import MembershipFactory from "./membership"; import MembershipFactory from "./membership";
export default abstract class MemberFactory { export default abstract class MemberFactory {
@ -10,14 +11,22 @@ export default abstract class MemberFactory {
*/ */
public static mapToSingle(record: member): MemberViewModel { public static mapToSingle(record: member): MemberViewModel {
return { return {
id: record.id, id: record?.id,
salutation: record.salutation, salutation: record?.salutation,
firstname: record.firstname, firstname: record?.firstname,
lastname: record.lastname, lastname: record?.lastname,
nameaffix: record.nameaffix, nameaffix: record?.nameaffix,
birthdate: record.birthdate, birthdate: record?.birthdate,
firstMembershipEntry: MembershipFactory.mapToSingle(record.firstMembershipEntry), firstMembershipEntry: record?.firstMembershipEntry
lastMembershipEntry: MembershipFactory.mapToSingle(record.lastMembershipEntry), ? 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,
}; };
} }

View file

@ -26,6 +26,15 @@ export default abstract class MemberService {
) )
.leftJoinAndSelect("membership_first.status", "status_first") .leftJoinAndSelect("membership_first.status", "status_first")
.leftJoinAndSelect("membership_last.status", "status_last") .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) .offset(offset)
.limit(count) .limit(count)
.orderBy("member.lastname") .orderBy("member.lastname")

View file

@ -12,7 +12,7 @@ export default abstract class MembershipService {
return await dataSource return await dataSource
.getRepository(membership) .getRepository(membership)
.createQueryBuilder("membership") .createQueryBuilder("membership")
.leftJoinAndSelect("membership.membership", "membership") .leftJoinAndSelect("membership.status", "membershipStatus")
.where("membership.memberId = :memberId", { memberId: memberId }) .where("membership.memberId = :memberId", { memberId: memberId })
.getMany() .getMany()
.then((res) => { .then((res) => {
@ -33,7 +33,7 @@ export default abstract class MembershipService {
return await dataSource return await dataSource
.getRepository(membership) .getRepository(membership)
.createQueryBuilder("membership") .createQueryBuilder("membership")
.leftJoinAndSelect("membership.membership", "membership") .leftJoinAndSelect("membership.status", "membershipStatus")
.where("membership.memberId = :memberId", { memberId: memberId }) .where("membership.memberId = :memberId", { memberId: memberId })
.andWhere("membership.id = :recordId", { recordId: recordId }) .andWhere("membership.id = :recordId", { recordId: recordId })
.getOneOrFail() .getOneOrFail()

View file

@ -1,4 +1,5 @@
import { Salutation } from "../../enums/salutation"; import { Salutation } from "../../enums/salutation";
import { CommunicationViewModel } from "./communication.models";
import { MembershipViewModel } from "./membership.models"; import { MembershipViewModel } from "./membership.models";
export interface MemberViewModel { export interface MemberViewModel {
@ -10,4 +11,6 @@ export interface MemberViewModel {
birthdate: Date; birthdate: Date;
firstMembershipEntry?: MembershipViewModel; firstMembershipEntry?: MembershipViewModel;
lastMembershipEntry?: MembershipViewModel; lastMembershipEntry?: MembershipViewModel;
sendNewsletter?: CommunicationViewModel;
preferredCommunication?: Array<CommunicationViewModel>;
} }