From 03cc0f02b7c22f9ce7f49102721f7fe777bb2538 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Wed, 8 Jan 2025 18:09:22 +0100 Subject: [PATCH 1/4] fix: member sorting at active members --- src/service/club/member/memberService.ts | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/service/club/member/memberService.ts b/src/service/club/member/memberService.ts index 4ac3a6d..969cbb9 100644 --- a/src/service/club/member/memberService.ts +++ b/src/service/club/member/memberService.ts @@ -120,17 +120,20 @@ export default abstract class MemberService { */ static async getByRunningMembership(): Promise> { return await dataSource - .getRepository(member) - .createQueryBuilder("member") - .leftJoinAndSelect("member.memberships", "membership") - .where("membership.end IS NULL") - .getMany() - .then((res) => { - return res; - }) - .catch((err) => { - throw new InternalException("member not found by id", err); - }); + .getRepository(member) + .createQueryBuilder("member") + .leftJoinAndSelect("member.memberships", "membership") + .where("membership.end IS NULL") + .orderBy("member.lastname") + .addOrderBy("member.firstname") + .addOrderBy("member.nameaffix") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new InternalException("member not found by id", err); + }); } /** -- 2.45.2 From 55d4a952c3b1cbfd2c91538b1e1f9efdb6485870 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Thu, 9 Jan 2025 12:38:07 +0100 Subject: [PATCH 2/4] change: minimize logging on custom errors --- src/middleware/errorHandler.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/middleware/errorHandler.ts b/src/middleware/errorHandler.ts index e3ce2ec..92e45ad 100644 --- a/src/middleware/errorHandler.ts +++ b/src/middleware/errorHandler.ts @@ -1,6 +1,7 @@ import { Request, Response } from "express"; import { ExceptionBase } from "../exceptions/exceptionsBaseType"; import CustomRequestException from "../exceptions/customRequestException"; +import UnauthorizedRequestException from "../exceptions/unauthorizedRequestException"; export default function errorHandler(err: ExceptionBase | Error, req: Request, res: Response, next: Function) { let status = 500; @@ -11,7 +12,11 @@ export default function errorHandler(err: ExceptionBase | Error, req: Request, r msg = err.message; } - console.log("Handler", err); + if (err instanceof CustomRequestException) { + console.log("Custom Handler", status, msg); + } else { + console.log("Error Handler", err); + } res.status(status).send(msg); } -- 2.45.2 From c173f917e38550da53be4e748368ebf3dfec038f Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Fri, 10 Jan 2025 11:26:48 +0100 Subject: [PATCH 3/4] fix: possibly undefined newsletter com --- src/controller/admin/club/memberController.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controller/admin/club/memberController.ts b/src/controller/admin/club/memberController.ts index dacbbae..807a911 100644 --- a/src/controller/admin/club/memberController.ts +++ b/src/controller/admin/club/memberController.ts @@ -48,8 +48,8 @@ import { UpdateCommunicationCommand, } from "../../../command/club/member/communicationCommand"; import CommunicationCommandHandler from "../../../command/club/member/communicationCommandHandler"; -import {PdfExport} from "../../../helpers/pdfExport"; -import {PermissionModule} from "../../../type/permissionTypes"; +import { PdfExport } from "../../../helpers/pdfExport"; +import { PermissionModule } from "../../../type/permissionTypes"; /** * @description get all members @@ -227,14 +227,14 @@ export async function getCommunicationByMemberAndRecord(req: Request, res: Respo * @returns {Promise<*>} */ export async function createMemberPrintoutList(req: Request, res: Response): Promise { - let members = await MemberService.getByRunningMembership() + let members = await MemberService.getByRunningMembership(); let pdf = await PdfExport.renderFile({ title: "Mitgliederliste", template: "member.list", saveToDisk: false, data: { - member: members + member: members, }, }); @@ -596,7 +596,7 @@ export async function updateCommunicationOfMember(req: Request, res: Response): communicationId: recordId, }; await MemberCommandHandler.updateNewsletter(updateNewsletter); - } else if (currentUserNewsletterMain.sendNewsletter.id == recordId) { + } else if (currentUserNewsletterMain.sendNewsletter?.id == recordId) { await MemberCommandHandler.unsetNewsletter(memberId); } -- 2.45.2 From 632a8290ace27aaf85fe3d0aa74a5ab8c010dbc6 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Fri, 10 Jan 2025 12:06:24 +0100 Subject: [PATCH 4/4] wrapping up: membership id transfer --- src/data-source.ts | 2 + src/entity/club/member/membership.ts | 6 --- src/migrations/1735822722235-internalId.ts | 40 +++++++++---------- .../1736505324488-finishInternalIdTransfer.ts | 23 +++++++++++ 4 files changed, 45 insertions(+), 26 deletions(-) create mode 100644 src/migrations/1736505324488-finishInternalIdTransfer.ts diff --git a/src/data-source.ts b/src/data-source.ts index 6810a53..4c4a424 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -66,6 +66,7 @@ import { PostalCode1735927918979 } from "./migrations/1735927918979-postalCode"; import { ProtocolAbsent1736072179716 } from "./migrations/1736072179716-protocolAbsent"; import { Memberlist1736079005086 } from "./migrations/1736079005086-memberlist"; import { ExtendViewValues1736084198860 } from "./migrations/1736084198860-extendViewValues"; +import { FinishInternalIdTransfer1736505324488 } from "./migrations/1736505324488-finishInternalIdTransfer"; const dataSource = new DataSource({ type: DB_TYPE as any, @@ -142,6 +143,7 @@ const dataSource = new DataSource({ ProtocolAbsent1736072179716, Memberlist1736079005086, ExtendViewValues1736084198860, + FinishInternalIdTransfer1736505324488, ], migrationsRun: true, migrationsTransactionMode: "each", diff --git a/src/entity/club/member/membership.ts b/src/entity/club/member/membership.ts index 9ed2e3a..aa14f27 100644 --- a/src/entity/club/member/membership.ts +++ b/src/entity/club/member/membership.ts @@ -7,12 +7,6 @@ export class membership { @PrimaryColumn({ generated: "increment", type: "int" }) id: number; - /** - * @deprecated - */ - @Column({ type: "varchar", length: 255, unique: true, nullable: true }) - internalId?: string; - @Column({ type: "date" }) start: Date; diff --git a/src/migrations/1735822722235-internalId.ts b/src/migrations/1735822722235-internalId.ts index 02063a2..9468b61 100644 --- a/src/migrations/1735822722235-internalId.ts +++ b/src/migrations/1735822722235-internalId.ts @@ -18,27 +18,27 @@ export class InternalId1735822722235 implements MigrationInterface { }) ); - let memberships = await queryRunner.manager.getRepository(membership).find(); - console.log(memberships); - let internalIds = memberships.reduce<{ [key: number]: Array }>((acc, cur) => { - let memberId = cur.memberId; - let setIds = acc[memberId] ?? []; - if (cur?.internalId) { - setIds.push(cur.internalId); - } - acc[memberId] = setIds; - return acc; - }, {}); + // let memberships = await queryRunner.manager.getRepository(membership).find(); + // console.log(memberships); + // let internalIds = memberships.reduce<{ [key: number]: Array }>((acc, cur) => { + // let memberId = cur.memberId; + // let setIds = acc[memberId] ?? []; + // if (cur?.internalId) { + // setIds.push(cur.internalId); + // } + // acc[memberId] = setIds; + // return acc; + // }, {}); - console.log(internalIds); - for (const [id, value] of Object.entries(internalIds)) { - const ids = value.filter((v) => v != null).join(", "); - if (ids) { - let m = await queryRunner.manager.getRepository(member).findOneByOrFail({ id: parseInt(id) }); - m.internalId = ids; - await queryRunner.manager.getRepository(member).save(m); - } - } + // console.log(internalIds); + // for (const [id, value] of Object.entries(internalIds)) { + // const ids = value.filter((v) => v != null).join(", "); + // if (ids) { + // let m = await queryRunner.manager.getRepository(member).findOneByOrFail({ id: parseInt(id) }); + // m.internalId = ids; + // await queryRunner.manager.getRepository(member).save(m); + // } + // } } public async down(queryRunner: QueryRunner): Promise { diff --git a/src/migrations/1736505324488-finishInternalIdTransfer.ts b/src/migrations/1736505324488-finishInternalIdTransfer.ts new file mode 100644 index 0000000..3c51c94 --- /dev/null +++ b/src/migrations/1736505324488-finishInternalIdTransfer.ts @@ -0,0 +1,23 @@ +import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"; + +export class FinishInternalIdTransfer1736505324488 implements MigrationInterface { + name = "FinishInternalIdTransfer1736505324488"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.dropColumn("membership", "internalId"); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.addColumn( + "membership", + new TableColumn({ + name: "internalId", + type: "varchar", + length: "255", + default: null, + isNullable: true, + isUnique: true, + }) + ); + } +} -- 2.45.2