feat: menambahkan akses slug ke beberapa fungsi yang belum terimplementasi
This commit is contained in:
@@ -194,6 +194,7 @@ class ProjectRepository {
|
|||||||
tasks: {
|
tasks: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
slug: true,
|
||||||
title: true,
|
title: true,
|
||||||
description: true,
|
description: true,
|
||||||
deadline_at: true,
|
deadline_at: true,
|
||||||
@@ -268,6 +269,7 @@ class ProjectRepository {
|
|||||||
project: {
|
project: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
slug: true,
|
||||||
project_name: true,
|
project_name: true,
|
||||||
project_icon: true,
|
project_icon: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -405,7 +405,9 @@ class ProjectService {
|
|||||||
const submission = task.submissions?.[0] || null;
|
const submission = task.submissions?.[0] || null;
|
||||||
return {
|
return {
|
||||||
id: task.id,
|
id: task.id,
|
||||||
|
slug: task.slug,
|
||||||
id_project: task.id_project,
|
id_project: task.id_project,
|
||||||
|
project_slug: task.project?.slug || null,
|
||||||
project_name: task.project?.project_name || null,
|
project_name: task.project?.project_name || null,
|
||||||
project_icon: task.project?.project_icon || null,
|
project_icon: task.project?.project_icon || null,
|
||||||
title: task.title,
|
title: task.title,
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ const { slugify } = require('../../../helpers/utils/slug');
|
|||||||
class TaskService {
|
class TaskService {
|
||||||
async createTask(idProject, payload, actor = {}) {
|
async createTask(idProject, payload, actor = {}) {
|
||||||
try {
|
try {
|
||||||
if (!this.isPositiveInteger(idProject)) {
|
if (!idProject) {
|
||||||
return error(new BadRequestError('Project ID must be a valid number'));
|
return error(new BadRequestError('Project ID or slug is required'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!actor?.id || !this.isMentorOrAdmin(actor)) {
|
if (!actor?.id || !this.isMentorOrAdmin(actor)) {
|
||||||
@@ -30,18 +30,16 @@ class TaskService {
|
|||||||
return error(new NotFoundError('Project not found'));
|
return error(new NotFoundError('Project not found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const taskSlug = await this.generateUniqueTaskSlug(project.id, payload.title);
|
const accessError = await this.validateProjectAccess(project.id, actor);
|
||||||
|
|
||||||
const accessError = await this.validateProjectAccess(idProject, actor);
|
|
||||||
|
|
||||||
if (accessError) {
|
if (accessError) {
|
||||||
return error(accessError);
|
return error(accessError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const taskSlug = await this.generateUniqueTaskSlug(project.id, payload.title);
|
||||||
const deadlineAt = this.buildDeadlineAt(payload.deadline_date, payload.specific_time);
|
const deadlineAt = this.buildDeadlineAt(payload.deadline_date, payload.specific_time);
|
||||||
|
|
||||||
const task = await taskRepository.createTask({
|
const task = await taskRepository.createTask({
|
||||||
id_project: parseInt(idProject),
|
id_project: project.id,
|
||||||
slug: taskSlug,
|
slug: taskSlug,
|
||||||
title: payload.title,
|
title: payload.title,
|
||||||
description: payload.description,
|
description: payload.description,
|
||||||
@@ -63,8 +61,8 @@ class TaskService {
|
|||||||
|
|
||||||
async getTasksByProject(idProject, actor = {}) {
|
async getTasksByProject(idProject, actor = {}) {
|
||||||
try {
|
try {
|
||||||
if (!this.isPositiveInteger(idProject)) {
|
if (!idProject) {
|
||||||
return error(new BadRequestError('Project ID must be a valid number'));
|
return error(new BadRequestError('Project ID or slug is required'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const project = await taskRepository.findProjectByIdOrSlug(idProject);
|
const project = await taskRepository.findProjectByIdOrSlug(idProject);
|
||||||
@@ -142,8 +140,8 @@ class TaskService {
|
|||||||
|
|
||||||
async updateTask(idTask, payload, actor = {}, projectIdentifier = null) {
|
async updateTask(idTask, payload, actor = {}, projectIdentifier = null) {
|
||||||
try {
|
try {
|
||||||
if (!this.isPositiveInteger(idTask)) {
|
if (!idTask) {
|
||||||
return error(new BadRequestError('Task ID must be a valid number'));
|
return error(new BadRequestError('Task ID or slug is required'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!actor?.id || !this.isMentorOrAdmin(actor)) {
|
if (!actor?.id || !this.isMentorOrAdmin(actor)) {
|
||||||
@@ -212,8 +210,8 @@ class TaskService {
|
|||||||
|
|
||||||
async deleteTask(idTask, actor = {}, projectIdentifier = null) {
|
async deleteTask(idTask, actor = {}, projectIdentifier = null) {
|
||||||
try {
|
try {
|
||||||
if (!this.isPositiveInteger(idTask)) {
|
if (!idTask) {
|
||||||
return error(new BadRequestError('Task ID must be a valid number'));
|
return error(new BadRequestError('Task ID or slug is required'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!actor?.id || !this.isMentorOrAdmin(actor)) {
|
if (!actor?.id || !this.isMentorOrAdmin(actor)) {
|
||||||
@@ -248,8 +246,8 @@ class TaskService {
|
|||||||
|
|
||||||
async submitTask(idTask, payload, file, actor = {}, projectIdentifier = null) {
|
async submitTask(idTask, payload, file, actor = {}, projectIdentifier = null) {
|
||||||
try {
|
try {
|
||||||
if (!this.isPositiveInteger(idTask)) {
|
if (!idTask) {
|
||||||
return error(new BadRequestError('Task ID must be a valid number'));
|
return error(new BadRequestError('Task ID or slug is required'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!actor?.id || actor.role !== 'intern') {
|
if (!actor?.id || actor.role !== 'intern') {
|
||||||
|
|||||||
Reference in New Issue
Block a user