Currently, I have a controller set up to handle an API call /task/:id/start. Within this controller method, the first step is to validate if the Task with the specified ID is valid. If it is determined to be valid, then I need to proceed by creating two other model instances: TaskSet
and TaskSetEvents
.
The creation process involves establishing a TaskSet
, followed by setting up a TaskSetEvent
. It's important to note that a TaskSetEvent
requires a TaskSet
to exist beforehand. The code snippet below outlines my current approach for handling these creations, although I'm open to suggestions on potential improvements:
TaskSet.create({ task: task}).exec(function(err, taskSet) {
TaskSetEvent.create({ taskSet: taskSet, eventType: 'start'}).exec(function (err, taskSetEvent) {
console.log("Everything created ok");
});
});