From 920ca3195fbacf7cdc9395732d7ef8961d0cb9e2 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 9 Mar 2025 02:30:28 +0900 Subject: [PATCH 1/3] fix: fix bug of Read Others Funding WISH-456 --- src/features/funding/funding.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/funding/funding.service.ts b/src/features/funding/funding.service.ts index 7fd200fe..ea4feb0f 100644 --- a/src/features/funding/funding.service.ts +++ b/src/features/funding/funding.service.ts @@ -101,7 +101,7 @@ export class FundingService { if (!friendship) { queryBuilder.andWhere( - 'fund.fundPubl = :publ', + 'funding.fundPubl = :publ', { publ: true } ) } From 6b40023991d779a3cecc365a002569e03ec92f34 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 9 Mar 2025 02:41:51 +0900 Subject: [PATCH 2/3] fix: read funding except User's from token WISH-457 --- src/features/funding/funding.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/funding/funding.service.ts b/src/features/funding/funding.service.ts index ea4feb0f..9e29043d 100644 --- a/src/features/funding/funding.service.ts +++ b/src/features/funding/funding.service.ts @@ -107,7 +107,7 @@ export class FundingService { } } } else { - queryBuilder.where('funding.fundUser != :userId', { userId }); + queryBuilder.where('funding.fundUser != :userId', { userId: user.userId }); const friendIds = await this.friendRepository .createQueryBuilder('friend') From 51b7562eade928c82a9f6083f4349ae214222599 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 9 Mar 2025 15:03:27 +0900 Subject: [PATCH 3/3] fix: change notification event handler WISH-458 --- .../donation/donation-event-handler.ts | 27 +++ src/event-handlers/event-handlers.module.ts | 8 + .../notification/notification.service.ts | 160 ------------------ 3 files changed, 35 insertions(+), 160 deletions(-) diff --git a/src/event-handlers/donation/donation-event-handler.ts b/src/event-handlers/donation/donation-event-handler.ts index 9022cb36..63231919 100644 --- a/src/event-handlers/donation/donation-event-handler.ts +++ b/src/event-handlers/donation/donation-event-handler.ts @@ -9,12 +9,22 @@ import { DonationRefundCancelledEvent } from 'src/features/donation/domain/event import { AdminAssignedForDonationRefundEvent } from 'src/features/donation/domain/events/admin-assigned-for-refune.event'; import { DonationRefundCompletedEvent } from 'src/features/donation/domain/events/donation-refund-completed.event'; import { DonationDeletedEvent } from 'src/features/donation/domain/events/donation-deleted.event'; +import { Notification } from 'src/entities/notification.entity'; +import { InjectRepository } from '@nestjs/typeorm'; +import { In, Repository } from 'typeorm'; +import { User } from 'src/entities/user.entity'; @Injectable() export class DonationEventHandler { constructor( private readonly notificationService: NotificationService, private readonly findAllAdmins: FindAllAdminsUseCase, + + @InjectRepository(Notification) + private notiRepository: Repository, + + @InjectRepository(User) + private userRepository: Repository, ) {} /** @@ -123,4 +133,21 @@ export class DonationEventHandler { await this.notificationService.createNoti(createNotificationDtoForDonor); } + + /** + * 새로운 후원이 추가되었을 때, 펀딩 게시시자에게 알림을 보냅니다. + */ + @OnEvent('NewDonate') + async handleNewDonate(data: {recvId: number, sendId: number, subId: string}) { + const noti = new Notification(); + const receiver = await this.userRepository.findOneBy({ userId: data.recvId }) + const sender = await this.userRepository.findOneBy({ userId: data.sendId }) + + noti.sendId = sender; + noti.recvId = receiver; + noti.notiType = NotiType.NewDonate; + noti.subId = data.subId; + + return await this.notiRepository.save(noti); + } } diff --git a/src/event-handlers/event-handlers.module.ts b/src/event-handlers/event-handlers.module.ts index 4f5ff551..b26c9aae 100644 --- a/src/event-handlers/event-handlers.module.ts +++ b/src/event-handlers/event-handlers.module.ts @@ -24,6 +24,10 @@ import { NotificationService } from 'src/features/notification/notification.serv import { ProvisionalDonationFsmService } from 'src/features/donation/domain/services/provisional-donation-fsm.service'; import { DepositFsmService } from 'src/features/deposit/domain/deposit-fsm.service'; import { DonationFsmService } from 'src/features/donation/domain/services/donation-fsm.service'; +import { FriendEventHandler } from './friend/friend-event-handler'; +import { FundEventHandler } from './fund/fund-event-handler'; +import { GratitudeEventHandler } from './gratitude/gratitude-event-handler'; +import { CommentEventHandler } from './comment/comment-event-handler'; const usecases = [ DeleteDonationUseCase, @@ -58,6 +62,10 @@ const services = [ DepositEventHandler, DonationEventHandler, ProvisionalDonationEventHandler, + CommentEventHandler, + FriendEventHandler, + FundEventHandler, + GratitudeEventHandler, ...usecases, ...services, ], diff --git a/src/features/notification/notification.service.ts b/src/features/notification/notification.service.ts index 60b9d2fe..4625e46d 100644 --- a/src/features/notification/notification.service.ts +++ b/src/features/notification/notification.service.ts @@ -10,7 +10,6 @@ import { NotiType } from 'src/enums/noti-type.enum'; import { Donation } from 'src/entities/donation.entity'; import { Funding } from 'src/entities/funding.entity'; import { OnEvent } from '@nestjs/event-emitter'; -import { FriendDto } from '../friend/dto/friend.dto'; import { ImageType } from 'src/enums/image-type.enum'; import { Image } from 'src/entities/image.entity'; @@ -106,165 +105,6 @@ export class NotificationService { }; } - @OnEvent('AcceptFollow') - async handleAcceptFollow(userId: number, friendDto: FriendDto) { - const noti1 = new Notification(); - const noti2 = new Notification(); - const receiver = await this.userRepository.findOneBy({ userId: friendDto.friendId }) - const sender = await this.userRepository.findOneBy({ userId: userId }) - - noti1.sendId = sender; - noti1.recvId = receiver; - noti2.sendId = receiver; - noti2.recvId = sender; - noti1.notiType = NotiType.NewFriend; - noti2.notiType = NotiType.NewFriend; - - if (!friendDto.notiId) { - const deleteNoti = await this.notiRepository.createQueryBuilder("notification") - .leftJoinAndSelect("notification.recvId", "receiver") - .where("notification.recvId = :recvId", { recvId: userId }) - .andWhere("notification.sendId = :sendId", { sendId: friendDto.friendId }) // 여기서 senderId는 숫자 타입이어야 합니다. - .andWhere("notification.notiType = :notiType", { notiType: NotiType.IncomingFollow }) - .getOne(); - - if (deleteNoti) { - await this.notiRepository.delete(deleteNoti.notiId); - }; - } else { - await this.notiRepository.delete(friendDto.notiId); - } - - await this.notiRepository.save(noti1); - await this.notiRepository.save(noti2); - - return; - } - - @OnEvent('IncomingFollow') - async handleIncomingFollow(userId: number, friendDto: FriendDto) { - const noti = new Notification(); - const receiver = await this.userRepository.findOneBy({ userId: friendDto.friendId }) - const sender = await this.userRepository.findOneBy({ userId: userId }) - - noti.sendId = sender; - noti.recvId = receiver; - noti.notiType = NotiType.IncomingFollow; - - return await this.notiRepository.save(noti); - } - - @OnEvent('FundClose') - async handleFundClose(fundId: number) { - const funding = await this.fundRepository.findOne({ - where: { fundId }, - relations: ['fundUser', 'donations', 'donations.user'] - }); - - // FundClose 알림 생성 및 저장 - const fundCloseNoti = new Notification(); - fundCloseNoti.recvId = funding.fundUser; - fundCloseNoti.notiType = NotiType.FundClose; - fundCloseNoti.subId = funding.fundUuid; - await this.notiRepository.save(fundCloseNoti); - - // DonatedFundClose 이벤트 처리, 기부자들에게 알림 생성 - if (funding.donations && funding.donations.length > 0) { - const notifications = funding.donations.map(donation => { - const noti = new Notification(); - noti.recvId = donation.user; // 받는 사람은 기부자 - noti.sendId = funding.fundUser; // 보내는 사람은 펀딩 주최자 - noti.notiType = NotiType.DonatedFundClose; // 알림 타입 설정 - noti.subId = funding.fundUuid; - - return this.notiRepository.save(noti); - }); - - // 모든 알림 저장 - await Promise.all(notifications); - } - } - - @OnEvent('FundAchieve') - async handleFundAchieve(data: {recvId: number, subId: string}) { - const noti = new Notification(); - const receiver = await this.userRepository.findOneBy({ userId: data.recvId }); - - noti.recvId = receiver; - noti.notiType = NotiType.FundAchieve; - noti.subId = data.subId; - - return await this.notiRepository.save(noti); - } - - @OnEvent('NewDonate') - async handleNewDonate(data: {recvId: number, sendId: number, subId: string}) { - const noti = new Notification(); - const receiver = await this.userRepository.findOneBy({ userId: data.recvId }) - const sender = await this.userRepository.findOneBy({ userId: data.sendId }) - - noti.sendId = sender; - noti.recvId = receiver; - noti.notiType = NotiType.NewDonate; - noti.subId = data.subId; - - return await this.notiRepository.save(noti); - } - - @OnEvent('WriteGratitude') - async handleWriteGratitude(fundId: number) { - const noti = new Notification(); - const funding = await this.fundRepository.findOne({ - where: { fundId }, - relations: ['fundUser'], - }); - - noti.recvId = funding.fundUser; - noti.notiType = NotiType.WriteGratitude; - noti.subId = funding.fundUuid; - - return this.notiRepository.save(noti); - } - - @OnEvent('CheckGratitude') - async handleCheckGratitude(fundId: number) { - const funding = await this.fundRepository.findOne({ - where: { fundId }, - relations: ['fundUser', 'donations', 'donations.user'] - }); - - // 해당 펀딩에 기여한 모든 사용자들에게 알림을 생성 - const notifications = funding.donations.map(donation => { - const noti = new Notification(); - noti.recvId = donation.user; // 받는 사람은 기부자 - noti.sendId = funding.fundUser; // 보내는 사람은 펀딩 주최자 - noti.notiType = NotiType.CheckGratitude; // 알림 타입 설정 - noti.subId = funding.fundUuid; - - return this.notiRepository.save(noti); - }); - - // 모든 알림을 비동기적으로 저장 - await Promise.all(notifications); - } - - @OnEvent('NewComment') - async handleNewComment(data: { fundId: number, authorId: number }) { - const noti = new Notification(); - const funding = await this.fundRepository.findOne({ - where: { fundId: data.fundId }, - relations: ['fundUser'], - }); - const sender = await this.userRepository.findOne({ where: { userId: data.authorId }}); - - noti.recvId = funding.fundUser; - noti.sendId = sender; - noti.notiType = NotiType.NewComment; - noti.subId = funding.fundUuid; - - return this.notiRepository.save(noti); - } - async createNoti( createNotiDto: CreateNotificationDto, ): Promise {