When a task is added to a study from the library (or a task is duplicated), a CustomizedTask is created in the db
It's not until the study is saved that the task bank is synced to the db
As a result, if you create a customized task and leave the page, it never gets linked to the study and is lost forever (just floating in the db with no reference to it)
Task
When a task is added to the task bank via the library or duplication (save as), link it to the study in the DB
What this means is add the task to the study's batteries field in the following 2 endpoints:
[x] 1. the endpoint to create a customized task (POST /tasks/:id/custom)
The :id in this endpoint is the id of the Battery, i.e. the task template, to create a customized version of
You'll need to provide the route with the study id somehow. Not sure what the best way is, but these could work:
Change to POST /tasks/:id/custom?studyId=xxx
Change to POST /studies/:studyId/tasks?taskId=xxx where taskId is the id of the Battery
[x] 2. the endpoint to save a task (PUT /tasks/custom/:id)
The :id in this endpoint is the id of the CustomizedBattery
You'll need to provide the route with the study id somehow. The RESTful way is probably to change the route to PUT /studies/:studyId/tasks/:taskId
Keep in mind that this endpoint is also used to save changes to already-existing tasks. We only need to add the task to the study if it's new
For an example of this pattern, see the route PUT /studies/:id, which has differing logic if the study is new
Problem
CustomizedTask
is created in the dbTask
batteries
field in the following 2 endpoints:POST /tasks/:id/custom
):id
in this endpoint is the id of theBattery
, i.e. the task template, to create a customized version ofPOST /tasks/:id/custom?studyId=xxx
POST /studies/:studyId/tasks?taskId=xxx
wheretaskId
is the id of theBattery
[x] 2. the endpoint to save a task (
PUT /tasks/custom/:id
):id
in this endpoint is the id of theCustomizedBattery
PUT /studies/:studyId/tasks/:taskId
PUT /studies/:id
, which has differing logic if the study is new