From e3ff3456ad0713730d6afe54eba6a35790559bb2 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Thu, 10 Apr 2025 10:02:32 +0200 Subject: [PATCH] fix: member commumication update --- .../member/communicationCommandHandler.ts | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/command/club/member/communicationCommandHandler.ts b/src/command/club/member/communicationCommandHandler.ts index 3899394..2890485 100644 --- a/src/command/club/member/communicationCommandHandler.ts +++ b/src/command/club/member/communicationCommandHandler.ts @@ -18,6 +18,17 @@ export default abstract class CommunicationCommandHandler { let insertId = -1; return await dataSource .transaction(async (manager) => { + if (createCommunication.isSendNewsletter) { + await manager + .createQueryBuilder() + .update(communication) + .set({ + isSendNewsletter: false, + }) + .where("memberId = :memberId", { memberId: createCommunication.memberId }) + .execute(); + } + await manager .createQueryBuilder() .insert() @@ -40,16 +51,6 @@ export default abstract class CommunicationCommandHandler { .then((result) => { insertId = result.identifiers[0].id; }); - - await manager - .createQueryBuilder() - .update(communication) - .set({ - isSendNewsletter: false, - }) - .where("memberId = :memberId", { memberId: createCommunication.memberId }) - .andWhere("id <> :id", { id: insertId }) - .execute(); }) .then(() => { return insertId; @@ -67,6 +68,17 @@ export default abstract class CommunicationCommandHandler { static async update(updateCommunication: UpdateCommunicationCommand): Promise { return await dataSource .transaction(async (manager) => { + if (updateCommunication.isSendNewsletter) { + await manager + .createQueryBuilder() + .update(communication) + .set({ + isSendNewsletter: false, + }) + .where("memberId = :memberId", { memberId: updateCommunication.memberId }) + .execute(); + } + await manager .createQueryBuilder() .update(communication) @@ -85,16 +97,6 @@ export default abstract class CommunicationCommandHandler { .where("id = :id", { id: updateCommunication.id }) .andWhere("memberId = :memberId", { memberId: updateCommunication.memberId }) .execute(); - - await manager - .createQueryBuilder() - .update(communication) - .set({ - isSendNewsletter: false, - }) - .where("memberId = :memberId", { memberId: updateCommunication.memberId }) - .andWhere("id <> :id", { id: updateCommunication.id }) - .execute(); }) .then(() => {}) .catch((err) => {