Merge pull request #35 from internship-humic/feat/certificate-api

fix: memberikan akses ke mentor untuk /project/{id_project} route
This commit is contained in:
Rafi Athallah
2026-07-10 16:32:22 +07:00
committed by GitHub
3 changed files with 307 additions and 5 deletions
@@ -221,10 +221,21 @@ class CertificateService {
async getProjectCertificates(id_project, actor) {
try {
if (!actor?.id) {
return error(new BadRequestError('Admin ID is required'));
return error(new BadRequestError('User ID is required'));
}
if (actor.role !== 'admin') {
const project = await certificateRepository.findProjectById(id_project);
if (!project) {
return error(new NotFoundError('Project not found'));
}
if (actor.role === 'mentor') {
if (project.id_admin !== parseInt(actor.id)) {
return error(
new ForbiddenError('Access denied: you are not the mentor of this project'),
);
}
} else if (actor.role !== 'admin') {
return error(
new ForbiddenError('Access denied: only admins/mentors can view project certificates'),
);