feat: menambahkan akses slug ke beberapa fungsi yang belum terimplementasi

This commit is contained in:
Muhammad Zhafran Ilham
2026-06-23 23:10:55 +07:00
parent 857b92d956
commit 8aedb19ca1
3 changed files with 17 additions and 15 deletions
@@ -194,6 +194,7 @@ class ProjectRepository {
tasks: {
select: {
id: true,
slug: true,
title: true,
description: true,
deadline_at: true,
@@ -268,6 +269,7 @@ class ProjectRepository {
project: {
select: {
id: true,
slug: true,
project_name: true,
project_icon: true,
},
@@ -405,7 +405,9 @@ class ProjectService {
const submission = task.submissions?.[0] || null;
return {
id: task.id,
slug: task.slug,
id_project: task.id_project,
project_slug: task.project?.slug || null,
project_name: task.project?.project_name || null,
project_icon: task.project?.project_icon || null,
title: task.title,
+13 -15
View File
@@ -16,8 +16,8 @@ const { slugify } = require('../../../helpers/utils/slug');
class TaskService {
async createTask(idProject, payload, actor = {}) {
try {
if (!this.isPositiveInteger(idProject)) {
return error(new BadRequestError('Project ID must be a valid number'));
if (!idProject) {
return error(new BadRequestError('Project ID or slug is required'));
}
if (!actor?.id || !this.isMentorOrAdmin(actor)) {
@@ -30,18 +30,16 @@ class TaskService {
return error(new NotFoundError('Project not found'));
}
const taskSlug = await this.generateUniqueTaskSlug(project.id, payload.title);
const accessError = await this.validateProjectAccess(idProject, actor);
const accessError = await this.validateProjectAccess(project.id, actor);
if (accessError) {
return error(accessError);
}
const taskSlug = await this.generateUniqueTaskSlug(project.id, payload.title);
const deadlineAt = this.buildDeadlineAt(payload.deadline_date, payload.specific_time);
const task = await taskRepository.createTask({
id_project: parseInt(idProject),
id_project: project.id,
slug: taskSlug,
title: payload.title,
description: payload.description,
@@ -63,8 +61,8 @@ class TaskService {
async getTasksByProject(idProject, actor = {}) {
try {
if (!this.isPositiveInteger(idProject)) {
return error(new BadRequestError('Project ID must be a valid number'));
if (!idProject) {
return error(new BadRequestError('Project ID or slug is required'));
}
const project = await taskRepository.findProjectByIdOrSlug(idProject);
@@ -142,8 +140,8 @@ class TaskService {
async updateTask(idTask, payload, actor = {}, projectIdentifier = null) {
try {
if (!this.isPositiveInteger(idTask)) {
return error(new BadRequestError('Task ID must be a valid number'));
if (!idTask) {
return error(new BadRequestError('Task ID or slug is required'));
}
if (!actor?.id || !this.isMentorOrAdmin(actor)) {
@@ -212,8 +210,8 @@ class TaskService {
async deleteTask(idTask, actor = {}, projectIdentifier = null) {
try {
if (!this.isPositiveInteger(idTask)) {
return error(new BadRequestError('Task ID must be a valid number'));
if (!idTask) {
return error(new BadRequestError('Task ID or slug is required'));
}
if (!actor?.id || !this.isMentorOrAdmin(actor)) {
@@ -248,8 +246,8 @@ class TaskService {
async submitTask(idTask, payload, file, actor = {}, projectIdentifier = null) {
try {
if (!this.isPositiveInteger(idTask)) {
return error(new BadRequestError('Task ID must be a valid number'));
if (!idTask) {
return error(new BadRequestError('Task ID or slug is required'));
}
if (!actor?.id || actor.role !== 'intern') {