From dd72f37856ee3f9f6cada8396f5163111c2983c7 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Fri, 3 Jan 2025 19:26:33 +0100 Subject: [PATCH] postal Code & commandHandler update --- src/command/communicationCommand.ts | 2 ++ src/command/communicationCommandHandler.ts | 20 ++++++----------- src/command/memberAwardCommandHandler.ts | 18 +++------------ .../memberExecutivePositionCommandHandler.ts | 18 +++------------ .../memberQualificationCommandHandler.ts | 18 +++------------ src/command/membershipCommandHandler.ts | 18 +++------------ src/controller/admin/memberController.ts | 5 ++++- src/data-source.ts | 2 ++ src/entity/communication.ts | 11 +++++++++- src/factory/admin/communication.ts | 1 + src/migrations/1735927918979-postalCode.ts | 22 +++++++++++++++++++ src/type/fieldTypes.ts | 10 ++++++++- src/viewmodel/admin/communication.models.ts | 1 + 13 files changed, 70 insertions(+), 76 deletions(-) create mode 100644 src/migrations/1735927918979-postalCode.ts diff --git a/src/command/communicationCommand.ts b/src/command/communicationCommand.ts index 6700110..f0fdd5a 100644 --- a/src/command/communicationCommand.ts +++ b/src/command/communicationCommand.ts @@ -3,6 +3,7 @@ export interface CreateCommunicationCommand { isSMSAlarming: boolean; mobile: string; email: string; + postalCode: string; city: string; street: string; streetNumber: number; @@ -17,6 +18,7 @@ export interface UpdateCommunicationCommand { isSMSAlarming: boolean; mobile: string; email: string; + postalCode: string; city: string; street: string; streetNumber: number; diff --git a/src/command/communicationCommandHandler.ts b/src/command/communicationCommandHandler.ts index c13bec6..9d18cc9 100644 --- a/src/command/communicationCommandHandler.ts +++ b/src/command/communicationCommandHandler.ts @@ -25,20 +25,13 @@ export default abstract class CommunicationCommandHandler { isSMSAlarming: createCommunication.isSMSAlarming, mobile: createCommunication.mobile, email: createCommunication.email, + postalCode: createCommunication.postalCode, city: createCommunication.city, street: createCommunication.street, streetNumber: createCommunication.streetNumber, streetNumberAddition: createCommunication.streetNumberAddition, - member: await dataSource - .getRepository(user) - .createQueryBuilder("user") - .where("id = :id", { id: createCommunication.memberId }) - .getOneOrFail(), - type: await dataSource - .getRepository(communicationType) - .createQueryBuilder("communication") - .where("id = :id", { id: createCommunication.typeId }) - .getOneOrFail(), + memberId: createCommunication.memberId, + typeId: createCommunication.typeId, }) .execute() .then((result) => { @@ -63,6 +56,7 @@ export default abstract class CommunicationCommandHandler { isSMSAlarming: updateCommunication.isSMSAlarming, mobile: updateCommunication.mobile, email: updateCommunication.email, + postalCode: updateCommunication.postalCode, city: updateCommunication.city, street: updateCommunication.street, streetNumber: updateCommunication.streetNumber, @@ -82,13 +76,13 @@ export default abstract class CommunicationCommandHandler { * @param DeleteCommunicationCommand * @returns {Promise} */ - static async delete(deletCommunication: DeleteCommunicationCommand): Promise { + static async delete(deleteCommunication: DeleteCommunicationCommand): Promise { return await dataSource .createQueryBuilder() .delete() .from(communication) - .where("id = :id", { id: deletCommunication.id }) - .andWhere("memberId = :memberId", { memberId: deletCommunication.memberId }) + .where("id = :id", { id: deleteCommunication.id }) + .andWhere("memberId = :memberId", { memberId: deleteCommunication.memberId }) .execute() .then(() => {}) .catch((err) => { diff --git a/src/command/memberAwardCommandHandler.ts b/src/command/memberAwardCommandHandler.ts index 79aeae4..775f55d 100644 --- a/src/command/memberAwardCommandHandler.ts +++ b/src/command/memberAwardCommandHandler.ts @@ -20,16 +20,8 @@ export default abstract class MemberAwardCommandHandler { given: createMemberAward.given, note: createMemberAward.note, date: createMemberAward.date, - member: await dataSource - .getRepository(member) - .createQueryBuilder("member") - .where("id = :id", { id: createMemberAward.memberId }) - .getOneOrFail(), - award: await dataSource - .getRepository(award) - .createQueryBuilder("award") - .where("id = :id", { id: createMemberAward.awardId }) - .getOneOrFail(), + memberId: createMemberAward.memberId, + awardId: createMemberAward.awardId, }) .execute() .then((result) => { @@ -53,11 +45,7 @@ export default abstract class MemberAwardCommandHandler { given: updateMemberAward.given, note: updateMemberAward.note, date: updateMemberAward.date, - award: await dataSource - .getRepository(award) - .createQueryBuilder("award") - .where("id = :id", { id: updateMemberAward.awardId }) - .getOneOrFail(), + award: updateMemberAward.awardId, }) .where("id = :id", { id: updateMemberAward.id }) .andWhere("memberId = :memberId", { memberId: updateMemberAward.memberId }) diff --git a/src/command/memberExecutivePositionCommandHandler.ts b/src/command/memberExecutivePositionCommandHandler.ts index e6f88b9..3d36a14 100644 --- a/src/command/memberExecutivePositionCommandHandler.ts +++ b/src/command/memberExecutivePositionCommandHandler.ts @@ -24,16 +24,8 @@ export default abstract class MemberExecutivePositionCommandHandler { note: createMemberExecutivePosition.note, start: createMemberExecutivePosition.start, end: createMemberExecutivePosition.end, - member: await dataSource - .getRepository(member) - .createQueryBuilder("member") - .where("id = :id", { id: createMemberExecutivePosition.memberId }) - .getOneOrFail(), - executivePosition: await dataSource - .getRepository(executivePosition) - .createQueryBuilder("executivePosition") - .where("id = :id", { id: createMemberExecutivePosition.executivePositionId }) - .getOneOrFail(), + memberId: createMemberExecutivePosition.memberId, + executivePositionId: createMemberExecutivePosition.executivePositionId, }) .execute() .then((result) => { @@ -57,11 +49,7 @@ export default abstract class MemberExecutivePositionCommandHandler { note: updateMemberExecutivePosition.note, start: updateMemberExecutivePosition.start, end: updateMemberExecutivePosition.end, - executivePosition: await dataSource - .getRepository(executivePosition) - .createQueryBuilder("executivePosition") - .where("id = :id", { id: updateMemberExecutivePosition.executivePositionId }) - .getOneOrFail(), + executivePositionId: updateMemberExecutivePosition.executivePositionId, }) .where("id = :id", { id: updateMemberExecutivePosition.id }) .andWhere("memberId = :memberId", { memberId: updateMemberExecutivePosition.memberId }) diff --git a/src/command/memberQualificationCommandHandler.ts b/src/command/memberQualificationCommandHandler.ts index 38f887d..7faad96 100644 --- a/src/command/memberQualificationCommandHandler.ts +++ b/src/command/memberQualificationCommandHandler.ts @@ -23,16 +23,8 @@ export default abstract class MemberQualificationCommandHandler { .values({ note: createMemberQualification.note, start: createMemberQualification.start, - member: await dataSource - .getRepository(member) - .createQueryBuilder("member") - .where("id = :id", { id: createMemberQualification.memberId }) - .getOneOrFail(), - qualification: await dataSource - .getRepository(qualification) - .createQueryBuilder("qualification") - .where("id = :id", { id: createMemberQualification.qualificationId }) - .getOneOrFail(), + memberId: createMemberQualification.memberId, + qualificationId: createMemberQualification.qualificationId, }) .execute() .then((result) => { @@ -57,11 +49,7 @@ export default abstract class MemberQualificationCommandHandler { start: updateMemberQualification.start, end: updateMemberQualification.end, terminationReason: updateMemberQualification.terminationReason, - qualification: await dataSource - .getRepository(qualification) - .createQueryBuilder("qualification") - .where("id = :id", { id: updateMemberQualification.qualificationId }) - .getOneOrFail(), + qualificationId: updateMemberQualification.qualificationId, }) .where("id = :id", { id: updateMemberQualification.id }) .andWhere("memberId = :memberId", { memberId: updateMemberQualification.memberId }) diff --git a/src/command/membershipCommandHandler.ts b/src/command/membershipCommandHandler.ts index 35a5262..b52a1dd 100644 --- a/src/command/membershipCommandHandler.ts +++ b/src/command/membershipCommandHandler.ts @@ -21,16 +21,8 @@ export default abstract class MembershipCommandHandler { .into(membership) .values({ start: createMembership.start, - member: await dataSource - .getRepository(member) - .createQueryBuilder("member") - .where("id = :id", { id: createMembership.memberId }) - .getOneOrFail(), - status: await dataSource - .getRepository(membershipStatus) - .createQueryBuilder("membershipStatus") - .where("id = :id", { id: createMembership.statusId }) - .getOneOrFail(), + memberId: createMembership.memberId, + statusId: createMembership.statusId, }) .execute() .then((result) => { @@ -70,11 +62,7 @@ export default abstract class MembershipCommandHandler { start: updateMembership.start, end: updateMembership.end, terminationReason: updateMembership.terminationReason, - status: await dataSource - .getRepository(membershipStatus) - .createQueryBuilder("membershipStatus") - .where("id = :id", { id: updateMembership.statusId }) - .getOneOrFail(), + statusId: updateMembership.statusId, }) .where("id = :id", { id: updateMembership.id }) .andWhere("memberId = :memberId", { memberId: updateMembership.memberId }) diff --git a/src/controller/admin/memberController.ts b/src/controller/admin/memberController.ts index c60ecc3..9aa6446 100644 --- a/src/controller/admin/memberController.ts +++ b/src/controller/admin/memberController.ts @@ -351,6 +351,7 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro const isSMSAlarming = req.body.isSMSAlarming; const mobile = req.body.mobile; const email = req.body.email; + const postalCode = req.body.postalCode; const city = req.body.city; const street = req.body.street; const streetNumber = req.body.streetNumber; @@ -363,6 +364,7 @@ export async function addCommunicationToMember(req: Request, res: Response): Pro isSMSAlarming, mobile, email, + postalCode, city, street, streetNumber, @@ -535,11 +537,11 @@ export async function updateCommunicationOfMember(req: Request, res: Response): const isSMSAlarming = req.body.isSMSAlarming; const mobile = req.body.mobile; const email = req.body.email; + const postalCode = req.body.postalCode; const city = req.body.city; const street = req.body.street; const streetNumber = req.body.streetNumber; const streetNumberAddition = req.body.streetNumberAddition; - const typeId = req.body.typeId; const isNewsletterMain = req.body.isNewsletterMain; let updateCommunication: UpdateCommunicationCommand = { @@ -548,6 +550,7 @@ export async function updateCommunicationOfMember(req: Request, res: Response): isSMSAlarming, mobile, email, + postalCode, city, street, streetNumber, diff --git a/src/data-source.ts b/src/data-source.ts index 75f6f5b..8074d2d 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -63,6 +63,7 @@ import { newsletterConfig } from "./entity/newsletterConfig"; import { NewsletterConfig1735207446910 } from "./migrations/1735207446910-newsletterConfig"; import { TemplateMargins1735733514043 } from "./migrations/1735733514043-templateMargins"; import { InternalId1735822722235 } from "./migrations/1735822722235-internalId"; +import { PostalCode1735927918979 } from "./migrations/1735927918979-postalCode"; const dataSource = new DataSource({ type: DB_TYPE as any, @@ -136,6 +137,7 @@ const dataSource = new DataSource({ NewsletterConfig1735207446910, TemplateMargins1735733514043, InternalId1735822722235, + PostalCode1735927918979, ], migrationsRun: true, migrationsTransactionMode: "each", diff --git a/src/entity/communication.ts b/src/entity/communication.ts index be006c1..df081be 100644 --- a/src/entity/communication.ts +++ b/src/entity/communication.ts @@ -1,4 +1,4 @@ -import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm"; +import { Column, Entity, ManyToOne, PrimaryColumn } from "typeorm"; import { member } from "./member"; import { communicationType } from "./communicationType"; @@ -19,6 +19,9 @@ export class communication { @Column({ type: "varchar", length: 255, nullable: true }) email: string; + @Column({ type: "varchar", length: 255, nullable: true }) + postalCode: string; + @Column({ type: "varchar", length: 255, nullable: true }) city: string; @@ -31,6 +34,12 @@ export class communication { @Column({ type: "varchar", length: 255, nullable: true }) streetNumberAddition: string; + @Column() + memberId: number; + + @Column() + typeId: number; + @ManyToOne(() => communicationType, (communicationType) => communicationType.communications, { nullable: false, onDelete: "RESTRICT", diff --git a/src/factory/admin/communication.ts b/src/factory/admin/communication.ts index 6fe454e..79b5f8a 100644 --- a/src/factory/admin/communication.ts +++ b/src/factory/admin/communication.ts @@ -14,6 +14,7 @@ export default abstract class CommunicationFactory { preferred: record.preferred, mobile: record.mobile, email: record.email, + postalCode: record.postalCode, city: record.city, street: record.street, streetNumber: record.streetNumber, diff --git a/src/migrations/1735927918979-postalCode.ts b/src/migrations/1735927918979-postalCode.ts new file mode 100644 index 0000000..e0dbbe5 --- /dev/null +++ b/src/migrations/1735927918979-postalCode.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"; + +export class PostalCode1735927918979 implements MigrationInterface { + name = "PostalCode1735927918979"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.addColumn( + "communication", + new TableColumn({ + name: "postalCode", + type: "varchar", + length: "255", + default: null, + isNullable: true, + }) + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropColumn("communication", "postalCode"); + } +} diff --git a/src/type/fieldTypes.ts b/src/type/fieldTypes.ts index 934d24d..b9105be 100644 --- a/src/type/fieldTypes.ts +++ b/src/type/fieldTypes.ts @@ -1,8 +1,16 @@ -export type CommunicationFieldType = "mobile" | "email" | "city" | "street" | "streetNumber" | "streetNumberAddition"; +export type CommunicationFieldType = + | "mobile" + | "email" + | "postalCode" + | "city" + | "street" + | "streetNumber" + | "streetNumberAddition"; export const communicationFieldTypes: Array = [ "mobile", "email", + "postalCode", "city", "street", "streetNumber", diff --git a/src/viewmodel/admin/communication.models.ts b/src/viewmodel/admin/communication.models.ts index 64295f8..b7f9dd7 100644 --- a/src/viewmodel/admin/communication.models.ts +++ b/src/viewmodel/admin/communication.models.ts @@ -5,6 +5,7 @@ export interface CommunicationViewModel { preferred: boolean; mobile: string; email: string; + postalCode: string; city: string; street: string; streetNumber: number; -- 2.45.2