Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

2.9 KB
Raw Blame
import { Router } from 'express';
import type { Routable } from '../../types/routable.type';
import { IsLoggedIn } from '../auth/middlewares/is-logged-in';
import { CanAddTaskNew } from './middlewares/CanAddTaskNew';
import { CanDeleteTask } from './middlewares/CanDeleteTask';
import { CanFetchTask } from './middlewares/CanFetchTask';
import { CanFetchTaskHistory } from './middlewares/CanFetchTaskHistory';
import { CanFetchTasks } from './middlewares/CanFetchTasks';
import { CanRecoveryTaskHistory } from './middlewares/CanRecoveryTaskHistory';
import { CanUpdateTask } from './middlewares/CanUpdateTask';
import { CanUpdateTaskAssigneeNew } from './middlewares/CanUpdateTaskAssigneeNew';
import { TasksController } from './TasksController';

export default class TasksRoutes implements Routable {
    private readonly router: ReturnType<typeof Router>;
    private readonly tasksController: TasksController;

    constructor() {
        this.router = Router();
        this.tasksController = new TasksController();
        this.initRoutes();
    }

    getRouter() {
        return this.router;
    }

    initRoutes() {
        /**
         * Fetch tasks (pagination is working properly)
         */
        this.router.get('', [IsLoggedIn, CanFetchTasks], this.tasksController.fetchTasksNew);

        /**
         * Fetch task by id
         */
        this.router.get('/:taskId', [IsLoggedIn, CanFetchTask], this.tasksController.fetchTaskByIdNew);

        /**
         * Update task
         */
        this.router.patch('', [IsLoggedIn, CanUpdateTask], this.tasksController.updateTask);

        /**
         * Toggle user for task
         */
        this.router.patch(
            '/task-users',
            [IsLoggedIn, CanUpdateTaskAssigneeNew],
            this.tasksController.toggleUserRolesNew
        );

        /**
         * Add new task
         */
        this.router.post('', [IsLoggedIn, CanAddTaskNew], this.tasksController.addTaskNew);

        /**
         * Delete task
         */
        this.router.delete('', [IsLoggedIn, CanDeleteTask], this.tasksController.deleteTaskNew);

        /**
         * Move a task (with its subtasks) to another project of the same organization. The planner checks both
         * projects; without the right to delete in the source project the task is copied instead.
         */
        this.router.get('/:taskId/move-preview', [IsLoggedIn], this.tasksController.previewMoveToProject);
        this.router.post('/move', [IsLoggedIn], this.tasksController.moveToProject);

        /**
         * Fetch task history
         */
        this.router.get('/:taskId/history', [IsLoggedIn, CanFetchTaskHistory], this.tasksController.fetchTaskHistory);

        /**
         * Restore task from history
         */
        this.router.post(
            '/:taskId/restore/:historyId',
            [IsLoggedIn, CanRecoveryTaskHistory],
            this.tasksController.recoverTaskHistory
        );
    }
}