(req, res)
| 305 | * @param res {Object} - Express response object |
| 306 | */ |
| 307 | const updateTask = async (req, res) => { |
| 308 | try { |
| 309 | const task = await tasks.fetchTask(req.params.id); |
| 310 | if (!task.taskData) { |
| 311 | return res.boom.notFound("Task not found"); |
| 312 | } |
| 313 | const requestData = { ...req.body, updatedAt: Math.round(Date.now() / 1000) }; |
| 314 | if (requestData?.assignee) { |
| 315 | const user = await dataAccess.retrieveUsers({ username: requestData.assignee }); |
| 316 | if (!user.userExists) { |
| 317 | return res.boom.notFound("User doesn't exist"); |
| 318 | } |
| 319 | if (!requestData?.startedOn) { |
| 320 | requestData.startedOn = Math.round(new Date().getTime() / 1000); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | await tasks.updateTask(requestData, req.params.id); |
| 325 | if (requestData.assignee) { |
| 326 | // New Assignee Status Update |
| 327 | await updateUserStatusOnTaskUpdate(requestData.assignee); |
| 328 | // Old Assignee Status Update if available |
| 329 | if (task.taskData.assigneeId) { |
| 330 | await updateStatusOnTaskCompletion(task.taskData.assigneeId); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return res.status(204).send(); |
| 335 | } catch (err) { |
| 336 | if (err.message.includes("Invalid dependency passed")) { |
| 337 | const errorMessage = "Invalid dependency"; |
| 338 | logger.error(`Error while updating task: ${errorMessage}`); |
| 339 | return res.boom.badRequest(errorMessage); |
| 340 | } |
| 341 | logger.error(`Error while updating task: ${err}`); |
| 342 | return res.boom.badImplementation(INTERNAL_SERVER_ERROR); |
| 343 | } |
| 344 | }; |
| 345 | |
| 346 | /** |
| 347 | * Updates self task status |
nothing calls this directly
no test coverage detected