feat: Nambahin feature notifikasi
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const taskRepository = require('../repositories/task.repository');
|
||||
const prisma = require('../../../helpers/db/db_connection');
|
||||
const notificationService = require('../../notification/services/notification.service');
|
||||
const { taskUploadDir } = require('../helpers/taskUpload.helper');
|
||||
const { data, error } = require('../../../helpers/utils/wrapper');
|
||||
const {
|
||||
@@ -43,6 +45,12 @@ class TaskService {
|
||||
submission_type: payload.submission_type,
|
||||
});
|
||||
|
||||
await notificationService.createNotificationForProjectInterns(
|
||||
idProject,
|
||||
"Tugas Baru Ditambahkan",
|
||||
`Mentor telah membuat tugas baru: '${task.title}' di proyek '${project.project_name}'.`
|
||||
).catch(err => console.error("Failed to send task creation notifications:", err));
|
||||
|
||||
return data(this.mapTask(task));
|
||||
} catch (err) {
|
||||
return error(err);
|
||||
@@ -114,7 +122,7 @@ class TaskService {
|
||||
return error(accessError);
|
||||
}
|
||||
|
||||
if (actor.role === 'admin') {
|
||||
if (this.isMentorOrAdmin(actor)) {
|
||||
return data(this.mapAdminTaskDetail(task));
|
||||
}
|
||||
|
||||
@@ -288,6 +296,21 @@ class TaskService {
|
||||
submission = await taskRepository.createSubmission(submissionData);
|
||||
}
|
||||
|
||||
const projectDetails = await taskRepository.findProjectById(task.id_project);
|
||||
if (projectDetails) {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: parseInt(actor.id) },
|
||||
select: { full_name: true }
|
||||
});
|
||||
const internName = user?.full_name || actor.email;
|
||||
|
||||
await notificationService.createNotificationForMentor(
|
||||
projectDetails.id_admin,
|
||||
"Pengiriman Tugas Baru",
|
||||
`Intern '${internName}' telah mengirimkan jawaban untuk tugas '${task.title}'.`
|
||||
).catch(err => console.error("Failed to send task submission notification:", err));
|
||||
}
|
||||
|
||||
return data(this.mapSubmission(submission));
|
||||
} catch (err) {
|
||||
return error(err);
|
||||
@@ -413,15 +436,15 @@ class TaskService {
|
||||
}
|
||||
|
||||
if (actor.role === 'mentor') {
|
||||
const project = await taskRepository.findProjectById(idProject);
|
||||
const project = await taskRepository.findProjectById(idProject);
|
||||
|
||||
if (!project || project.id_admin !== parseInt(actor.id)) {
|
||||
return new ForbiddenError('Access denied: you are not the mentor of this project');
|
||||
}
|
||||
|
||||
return null;
|
||||
if (!project || project.id_admin !== parseInt(actor.id)) {
|
||||
return new ForbiddenError('Access denied: you are not the mentor of this project');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (actor.role === 'intern') {
|
||||
const membership = await taskRepository.checkActiveProjectMember(idProject, actor.id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user