fix(core): keep module tasks on updates that do not state a task list
Problem
OrganizationProjectModuleService.update() destructured tasks = [], so an edit that only changed, for example, the name or status of a module treated the missing task list as "remove every task". The module's tasks were loaded without their own modules relation, so each one was saved with modules: [] and was unlinked from every other module as well. On top of that, the "tasks to add" were the stated tasks that were not found in the database, so a stated existing task that was not yet in the module was never added through the task side. The GraphQL resolver already documents that an unstated task list leaves the task set as it is.
Fix
- Only sync tasks when the update states a task list (
Array.isArray(entity.tasks)). - Tasks to add are the stated tasks found in the database that are not yet in the module.
- Tasks to remove are reloaded with their modules (as
assignTasksToModuledoes) and only the pairing with this module is dropped. - Task updates only send
modulesinstead of the whole task object.
Tests
organization-project-module.service.update-tasks.spec.ts: an update without tasks does not touch any task; a stated existing task not yet in the module is added; an unstated task keeps its other modules.
Not built or run locally (no local node_modules).
Summary by cubic
Fixes OrganizationProjectModuleService.update() so an edit that doesn't state a task list no longer removes the module's tasks.
Previously, a missing tasks field was treated as an empty list, so any rename or status change stripped all tasks, and because tasks were loaded without their own modules relation, each was saved with modules: [] and unlinked from every module. The update now matches the documented behavior: an unstated task list leaves the task set untouched.
- Only syncs tasks when the update actually states a task list.
- Adds stated tasks found in the database that aren't yet in the module.
- Reloads tasks to remove with their modules, dropping only the pairing with this module.
- Sends only
modulesin task updates instead of the whole task object. - Adds tests for leaving tasks untouched, adding a stated existing task, and keeping other modules on removal.