(req, res, next)
| 349 | * @param res {Object} - Express response object |
| 350 | */ |
| 351 | const updateTaskStatus = async (req, res, next) => { |
| 352 | try { |
| 353 | req.body.updatedAt = Math.round(new Date().getTime() / 1000); |
| 354 | let userStatusUpdate; |
| 355 | const taskId = req.params.id; |
| 356 | const { userStatusFlag } = req.query; |
| 357 | const status = req.body?.status; |
| 358 | const { id: userId, username } = req.userData; |
| 359 | const task = await tasks.fetchSelfTask(taskId, userId); |
| 360 | |
| 361 | if (task.taskNotFound) return res.boom.notFound("Task doesn't exist"); |
| 362 | if (task.notAssignedToYou) return res.boom.forbidden("This task is not assigned to you"); |
| 363 | if (TASK_STATUS.BACKLOG === status) { |
| 364 | return res.boom.forbidden("Status cannot be updated. Please contact admin."); |
| 365 | } |
| 366 | if (userStatusFlag) { |
| 367 | if (task.taskData.status === TASK_STATUS.DONE) { |
| 368 | return res.boom.forbidden("Status cannot be updated. Please contact admin."); |
| 369 | } |
| 370 | if (status) { |
| 371 | const isCurrentTaskStatusInProgress = task.taskData.status === TASK_STATUS.IN_PROGRESS; |
| 372 | const isCurrentTaskStatusBlock = task.taskData.status === TASK_STATUS.BLOCKED; |
| 373 | const isNewTaskStatusInProgress = status === TASK_STATUS.IN_PROGRESS; |
| 374 | const isNewTaskStatusBlock = status === TASK_STATUS.BLOCKED; |
| 375 | const isCurrProgress100 = parseInt(task.taskData.percentCompleted || 0) === 100; |
| 376 | const isCurrProgress0 = parseInt(task.taskData.percentCompleted || 0) === 0; |
| 377 | const isNewProgress100 = !!req.body.percentCompleted && parseInt(req.body.percentCompleted) === 100; |
| 378 | const isNewProgress0 = !!req.body.percentCompleted !== undefined && parseInt(req.body.percentCompleted) === 0; |
| 379 | |
| 380 | if ( |
| 381 | !isCurrProgress100 && |
| 382 | !isNewProgress100 && |
| 383 | (isCurrentTaskStatusBlock || isCurrentTaskStatusInProgress) && |
| 384 | !isNewTaskStatusBlock && |
| 385 | !isNewTaskStatusInProgress |
| 386 | ) { |
| 387 | return res.boom.badRequest( |
| 388 | `The status of task can not be changed from ${ |
| 389 | isCurrentTaskStatusInProgress ? "In progress" : "Blocked" |
| 390 | } until progress of task is not 100%.` |
| 391 | ); |
| 392 | } |
| 393 | if (isNewTaskStatusInProgress && !isCurrentTaskStatusBlock && !isCurrProgress0 && !isNewProgress0) { |
| 394 | return res.boom.badRequest( |
| 395 | "The status of task can not be changed to In progress until progress of task is not 0%." |
| 396 | ); |
| 397 | } |
| 398 | } |
| 399 | } else { |
| 400 | if (task.taskData.status === TASK_STATUS.VERIFIED || TASK_STATUS.MERGED === status) { |
| 401 | return res.boom.forbidden("Status cannot be updated. Please contact admin."); |
| 402 | } |
| 403 | if (task.taskData.status === TASK_STATUS.COMPLETED && req.body.percentCompleted < 100) { |
| 404 | if (status === TASK_STATUS.COMPLETED || !status) { |
| 405 | return res.boom.badRequest("Task percentCompleted can't updated as status is COMPLETED"); |
| 406 | } |
| 407 | } |
| 408 | if ( |
nothing calls this directly
no test coverage detected