fix: member commumication update
This commit is contained in:
parent
a660642bbb
commit
e3ff3456ad
1 changed files with 22 additions and 20 deletions
|
@ -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<void> {
|
||||
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) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue