feat(project): menambahkan endpoint assignable interns untuk admin atau mentor
This commit is contained in:
@@ -247,6 +247,34 @@ class ProjectController {
|
||||
}
|
||||
}
|
||||
|
||||
async getAssignableInterns(req, res) {
|
||||
try {
|
||||
const actor = getActor(req);
|
||||
|
||||
const result = await projectService.getAssignableInterns(actor);
|
||||
|
||||
if (result.err) {
|
||||
return response(res, "fail", result);
|
||||
}
|
||||
|
||||
return response(
|
||||
res,
|
||||
"success",
|
||||
result,
|
||||
"Assignable interns retrieved successfully",
|
||||
SUCCESS.OK
|
||||
);
|
||||
} catch (err) {
|
||||
return response(
|
||||
res,
|
||||
"fail",
|
||||
error(new InternalServerError(err.message)),
|
||||
"Unexpected error occurred",
|
||||
ERROR.INTERNAL_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async assignMember(req, res) {
|
||||
try {
|
||||
const actor = getActor(req);
|
||||
|
||||
@@ -404,6 +404,38 @@ class ProjectRepository {
|
||||
});
|
||||
}
|
||||
|
||||
async findAssignableInterns() {
|
||||
return prisma.user.findMany({
|
||||
where: {
|
||||
role: "intern",
|
||||
is_active: true,
|
||||
project_members: {
|
||||
none: {
|
||||
status: "active",
|
||||
project: {
|
||||
status: "active",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
full_name: "asc",
|
||||
},
|
||||
include: {
|
||||
lamaran_magang: {
|
||||
include: {
|
||||
lowongan_magang: {
|
||||
select: {
|
||||
posisi: true,
|
||||
kelompok_peminatan: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async assignMember(id_project, id_user) {
|
||||
return prisma.projectMember.create({
|
||||
data: {
|
||||
|
||||
@@ -559,6 +559,42 @@ class ProjectService {
|
||||
}
|
||||
}
|
||||
|
||||
async getAssignableInterns(actor = {}) {
|
||||
try {
|
||||
if (!actor?.id) {
|
||||
return error(new BadRequestError("Admin ID is required"));
|
||||
}
|
||||
|
||||
if (actor.role !== "admin" && actor.role !== "mentor") {
|
||||
return error(
|
||||
new ForbiddenError("Access denied: only mentors/admins can view assignable interns")
|
||||
);
|
||||
}
|
||||
|
||||
const interns = await projectRepository.findAssignableInterns();
|
||||
|
||||
const mappedInterns = interns.map((intern) => {
|
||||
const lowongan = intern.lamaran_magang?.lowongan_magang;
|
||||
|
||||
return {
|
||||
id: intern.id,
|
||||
full_name: intern.full_name,
|
||||
email: intern.email,
|
||||
professional_bio: intern.professional_bio || null,
|
||||
position: lowongan?.posisi || intern.intern_position || null,
|
||||
kelompok_peminatan:
|
||||
lowongan?.kelompok_peminatan || intern.intern_interest_group || null,
|
||||
is_active: intern.is_active,
|
||||
is_assignable: true,
|
||||
};
|
||||
});
|
||||
|
||||
return data(mappedInterns);
|
||||
} catch (err) {
|
||||
return error(err);
|
||||
}
|
||||
}
|
||||
|
||||
async assignMember(payload, actor = {}) {
|
||||
try {
|
||||
if (!actor?.id) {
|
||||
|
||||
Reference in New Issue
Block a user