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: "",
transformer: {
from(value: string): Array<string> {
return value.split(",");
return (value ?? "").split(",");
},
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 { 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<communication>;
}

View file

@ -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,
};
}

View file

@ -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,
};
}

View file

@ -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")

View file

@ -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()

View file

@ -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<CommunicationViewModel>;
}