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.

685 B
Raw Blame
import { TaskFieldPermissionsForWatching } from './tasks.server.types';
import type { HideUnwatchableTaskFieldsArgs, TaskWatchableField } from './tasks.server.types';

/** Nulls every task field the checker does not allow to watch; mutates and returns the task. */
export function hideUnwatchableTaskFields<T extends object>(args: HideUnwatchableTaskFieldsArgs<T>): T {
    const task = args.task as Record<TaskWatchableField, unknown>;
    (Object.keys(TaskFieldPermissionsForWatching) as TaskWatchableField[]).forEach((key) => {
        if (!args.checker.hasPermissions(TaskFieldPermissionsForWatching[key])) {
            task[key] = null;
        }
    });
    return args.task;
}