Skip to content

Commit b5af12b

Browse files
committed
Merge branch 'feat/#377', remote-tracking branch 'origin' into develop
2 parents 654f490 + 8c8935a commit b5af12b

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE `Notification` MODIFY `type` ENUM('FOLLOW', 'NEW_PROMPT', 'INQUIRY', 'ANNOUNCEMENT', 'REPORT', 'ADMIN_MESSAGE') NOT NULL;

prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ enum NotificationType {
501501
INQUIRY
502502
ANNOUNCEMENT
503503
REPORT
504+
ADMIN_MESSAGE
504505
}
505506

506507
enum Payment_provider {

src/messages/services/message.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Service } from "typedi";
22
import { CreateMessageDto } from "../dtos/message.dto";
33
import { MessageRepository } from "../repositories/message.repository";
44
import { AppError } from "../../errors/AppError";
5+
import eventBus from "../../config/eventBus";
56

67
@Service()
78
export class MessageService {
@@ -114,6 +115,9 @@ async sendMessage(currentUserId: number, data: CreateMessageDto) {
114115

115116
const message = await this.messageRepository.createMessage(data);
116117

118+
// 새 관리자 메세지 알림 이벤트 발생
119+
eventBus.emit('adminMessage.created', data.sender_id, data.receiver_id, data.body);
120+
117121
return {
118122
message: "메시지 전송 성공",
119123
message_id: message.message_id,

src/notifications/listeners/notification.listener.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createFollowNotification,
66
createInquiryNotification,
77
createPromptNotification,
8+
createAdminMessageNtification
89
} from "../services/notification.service";
910

1011

@@ -52,4 +53,15 @@ eventBus.on('prompt.created', async (prompterId: number, promptId: number) => {
5253
} catch (err) {
5354
console.error("[알림 리스너 오류]: 새로운 프롬프트 업로드 알림 생성 실패", err);
5455
}
55-
});
56+
});
57+
58+
59+
// 관리자 메세지 알림 리스너
60+
eventBus.on('adminMessage.created', async( adminId: number, userId: number, content: string) => {
61+
try {
62+
await createAdminMessageNtification(adminId, userId, content);
63+
} catch (err) {
64+
console.error("[알림 리스너 오류]: 관리자 메세지 알림 생성 실패", err);
65+
}
66+
67+
})

src/notifications/repositories/notification.repository.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export const createNotification = async ({
100100
});
101101
};
102102

103-
// ==========알림 목록 조회==========
104103
// ==========알림 목록 조회==========
105104
export const findNotificationsByUserId = async (
106105
userId: number,
@@ -131,9 +130,9 @@ export const findNotificationsByUserId = async (
131130
}),
132131
});
133132

134-
// 2. FOLLOW / NEW_PROMPT 알림에 대해 profileImage 조회
133+
// profileImage 조회
135134
const actorIdsToFetch = notifications
136-
.filter(n => (n.type === 'FOLLOW' || n.type === 'NEW_PROMPT') && n.actor)
135+
.filter(n => (n.type === 'FOLLOW' || n.type === 'NEW_PROMPT' || n.type === 'ADMIN_MESSAGE') && n.actor)
137136
.map(n => n.actor!.user_id);
138137

139138
let actorProfilesMap: Record<number, { url: string } | null> = {};
@@ -160,7 +159,7 @@ export const findNotificationsByUserId = async (
160159
? {
161160
...n.actor,
162161
profileImage:
163-
n.type === 'FOLLOW' || n.type === 'NEW_PROMPT'
162+
n.type === 'FOLLOW' || n.type === 'NEW_PROMPT' || n.type === 'ADMIN_MESSAGE'
164163
? actorProfilesMap[n.actor.user_id] ?? null
165164
: null,
166165
}

src/notifications/services/notification.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,16 @@ export const getNotificationHasNewStatusService = async (
235235
const hasNew = latestNotificationTime > lastNotificationCheckTime;
236236

237237
return { hasNew };
238-
};
238+
};
239+
240+
// 관리자 메세지 알림
241+
export const createAdminMessageNtification = async( adminId: number, userId: number, content: string) => {
242+
243+
return createNotificationService({
244+
userId,
245+
type: NotificationType.ADMIN_MESSAGE,
246+
content: content,
247+
linkUrl: null,
248+
actorId: adminId,
249+
});
250+
}

0 commit comments

Comments
 (0)