Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion controllers/notificationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion repositorys/notificationRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
Expand Down
11 changes: 9 additions & 2 deletions services/notificationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Loading