Merge pull request #32 from internship-humic/feat/notification-system
feat: nambahin link field di Notification
This commit is contained in:
@@ -5,13 +5,14 @@ const { data, error } = require('../../../helpers/utils/wrapper');
|
||||
const { NotFoundError, ForbiddenError, BadRequestError } = require('../../../helpers/error');
|
||||
|
||||
class NotificationService {
|
||||
async createNotificationForIntern(userId, title, message) {
|
||||
async createNotificationForIntern(userId, title, message, link = '') {
|
||||
try {
|
||||
const notification = await notificationRepository.create({
|
||||
id_user: parseInt(userId),
|
||||
id_admin: null,
|
||||
title,
|
||||
message,
|
||||
link,
|
||||
is_read: false
|
||||
});
|
||||
|
||||
@@ -26,13 +27,14 @@ class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
async createNotificationForMentor(adminId, title, message) {
|
||||
async createNotificationForMentor(adminId, title, message, link = '') {
|
||||
try {
|
||||
const notification = await notificationRepository.create({
|
||||
id_user: null,
|
||||
id_admin: parseInt(adminId),
|
||||
title,
|
||||
message,
|
||||
link,
|
||||
is_read: false
|
||||
});
|
||||
|
||||
@@ -47,7 +49,7 @@ class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
async createNotificationForProjectInterns(projectId, title, message) {
|
||||
async createNotificationForProjectInterns(projectId, title, message, link = '') {
|
||||
try {
|
||||
const project = await taskRepository.findProjectById(projectId);
|
||||
if (!project || !project.members) {
|
||||
@@ -56,7 +58,7 @@ class NotificationService {
|
||||
|
||||
const results = [];
|
||||
for (const member of project.members) {
|
||||
const res = await this.createNotificationForIntern(member.id_user, title, message);
|
||||
const res = await this.createNotificationForIntern(member.id_user, title, message, link);
|
||||
if (res.data) {
|
||||
results.push(res.data);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,8 @@ class ProjectService {
|
||||
await notificationService.createNotificationForIntern(
|
||||
idUser,
|
||||
"Diterima ke Proyek",
|
||||
`Anda telah bergabung ke proyek '${project.project_name}'.`
|
||||
`Anda telah bergabung ke proyek '${project.project_name}'.`,
|
||||
`/intern/projects/${project.slug}`
|
||||
).catch(err => console.error("Failed to send project assignment notification:", err));
|
||||
}
|
||||
|
||||
@@ -711,7 +712,8 @@ class ProjectService {
|
||||
await notificationService.createNotificationForIntern(
|
||||
id_user,
|
||||
"Diterima ke Proyek",
|
||||
`Anda telah bergabung ke proyek '${project.project_name}'.`
|
||||
`Anda telah bergabung ke proyek '${project.project_name}'.`,
|
||||
`/intern/projects/${project.slug}`
|
||||
).catch(err => console.error("Failed to send project assignment notification:", err));
|
||||
|
||||
return data(membership);
|
||||
|
||||
@@ -55,7 +55,8 @@ class TaskService {
|
||||
await notificationService.createNotificationForProjectInterns(
|
||||
project.id,
|
||||
"Tugas Baru Ditambahkan",
|
||||
`Mentor telah membuat tugas baru: '${task.title}' di proyek '${project.project_name}'.`
|
||||
`Mentor telah membuat tugas baru: '${task.title}' di proyek '${project.project_name}'.`,
|
||||
`/intern/projects/${project.slug}/${task.slug}`
|
||||
).catch(err => console.error("Failed to send task creation notifications:", err));
|
||||
|
||||
return data(this.mapTask(task));
|
||||
|
||||
Reference in New Issue
Block a user