feat: implementasi slug di module task

This commit is contained in:
Muhammad Zhafran Ilham
2026-06-23 22:40:41 +07:00
parent b630ebbe3c
commit 857b92d956
4 changed files with 218 additions and 32 deletions
@@ -59,6 +59,8 @@ class TaskRepository {
project: {
select: {
id: true,
id_admin: true,
slug: true,
project_name: true,
project_icon: true,
members: {
@@ -194,6 +196,100 @@ class TaskRepository {
},
});
}
async findProjectByIdOrSlug(identifier) {
if (/^\d+$/.test(String(identifier))) {
return this.findProjectById(identifier);
}
return prisma.project.findUnique({
where: {
slug: identifier,
},
include: {
members: {
where: {
status: 'active',
},
select: {
id: true,
id_user: true,
},
},
},
});
}
async findTaskBySlug(idProject, slug) {
return prisma.task.findUnique({
where: {
id_project_slug: {
id_project: parseInt(idProject),
slug,
},
},
include: {
project: {
select: {
id: true,
id_admin: true,
slug: true,
project_name: true,
project_icon: true,
members: {
where: {
status: 'active',
},
include: {
user: {
select: {
id: true,
full_name: true,
email: true,
professional_bio: true,
},
},
},
},
},
},
submissions: {
include: {
user: {
select: {
id: true,
full_name: true,
email: true,
professional_bio: true,
},
},
},
},
},
});
}
async findTaskSlugExists(idProject, slug, excludeTaskId = null) {
const where = {
id_project: parseInt(idProject),
slug,
};
if (excludeTaskId) {
where.id = {
not: parseInt(excludeTaskId),
};
}
const task = await prisma.task.findFirst({
where,
select: {
id: true,
},
});
return Boolean(task);
}
}
module.exports = new TaskRepository();