feat: menambahkan kolom slug dan implement slug di module project

This commit is contained in:
Muhammad Zhafran Ilham
2026-06-23 22:07:21 +07:00
parent 08f7ca8319
commit b630ebbe3c
6 changed files with 138 additions and 11 deletions
@@ -420,6 +420,44 @@ class ProjectRepository {
},
});
}
async findBySlug(slug) {
return prisma.project.findUnique({
where: {
slug,
},
include: this.projectDetailInclude(),
});
}
async findByIdOrSlug(identifier) {
if (/^\d+$/.test(String(identifier))) {
return this.findById(identifier);
}
return this.findBySlug(identifier);
}
async findSlugExists(slug, excludeProjectId = null) {
const where = {
slug,
};
if (excludeProjectId) {
where.id = {
not: parseInt(excludeProjectId),
};
}
const project = await prisma.project.findFirst({
where,
select: {
id: true,
},
});
return Boolean(project);
}
}
module.exports = new ProjectRepository();