diff --git a/controllers/notificationController.js b/controllers/notificationController.js index 4d4b5cb..344f86f 100644 --- a/controllers/notificationController.js +++ b/controllers/notificationController.js @@ -90,7 +90,9 @@ const createNotification = async (req, res) => { try { const notification = await notificationService.createNotification( parseInt(targetUserId), - message + message, + notificationType, + url ); const io = req.app.get('io'); io.emit('notification', { diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9663156..8a6f6d5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -122,6 +122,8 @@ model notification { user user? @relation(fields: [user_id], references: [id]) content String user_id Int? + url String? + type String? read Boolean } diff --git a/repositorys/notificationRepository.js b/repositorys/notificationRepository.js index 66ab32f..e88d825 100644 --- a/repositorys/notificationRepository.js +++ b/repositorys/notificationRepository.js @@ -64,11 +64,18 @@ const getNotificationCount = async (userId) => { return { unreadCount: notificationCount }; }; -const createNotification = async (targetUserId, message) => { +const createNotification = async ( + targetUserId, + message, + notificationType, + url +) => { const notification = await prisma.notification.create({ data: { user_id: targetUserId, content: message, + type: notificationType, + url: url, read: false, }, }); diff --git a/services/notificationService.js b/services/notificationService.js index f8620de..086bd42 100644 --- a/services/notificationService.js +++ b/services/notificationService.js @@ -39,10 +39,17 @@ const getNotificationCount = async (userId) => { return notificationCount; }; -const createNotification = async (targetUserId, message) => { +const createNotification = async ( + targetUserId, + message, + notificationType, + url +) => { const notification = await notificationRepository.createNotification( targetUserId, - message + message, + notificationType, + url ); return notification; };