feat: menambahkan kolom slug dan implement slug di module project
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user