@@ -289,18 +289,6 @@ const updateTask = async (req, res) => {
289
289
}
290
290
}
291
291
292
- // currently the task is assigned to a user and the superuser is trying to un assign this task from them.
293
- if (
294
- requestData ?. status === TASK_STATUS . AVAILABLE &&
295
- task . taskData . status !== TASK_STATUS . AVAILABLE &&
296
- Object . keys ( req . body ) . length === 1
297
- ) {
298
- requestData . assignee = null ;
299
- requestData . percentCompleted = 0 ;
300
- requestData . startedOn = null ;
301
- requestData . endsOn = null ;
302
- }
303
-
304
292
await tasks . updateTask ( requestData , req . params . id ) ;
305
293
if ( requestData . assignee ) {
306
294
// New Assignee Status Update
@@ -334,38 +322,40 @@ const updateTaskStatus = async (req, res, next) => {
334
322
let userStatusUpdate ;
335
323
const taskId = req . params . id ;
336
324
const { userStatusFlag } = req . query ;
325
+ const status = req . body ?. status ;
337
326
const { id : userId , username } = req . userData ;
338
327
const task = await tasks . fetchSelfTask ( taskId , userId ) ;
339
328
340
329
if ( task . taskNotFound ) return res . boom . notFound ( "Task doesn't exist" ) ;
341
330
if ( task . notAssignedToYou ) return res . boom . forbidden ( "This task is not assigned to you" ) ;
342
- if ( task . taskData . status === TASK_STATUS . VERIFIED || req . body . status === TASK_STATUS . MERGED )
331
+ if (
332
+ task . taskData . status === TASK_STATUS . VERIFIED ||
333
+ status === TASK_STATUS . MERGED ||
334
+ status === TASK_STATUS . BACKLOG
335
+ )
343
336
return res . boom . forbidden ( "Status cannot be updated. Please contact admin." ) ;
344
337
345
338
if ( userStatusFlag ) {
346
339
if ( task . taskData . status === TASK_STATUS . DONE && req . body . percentCompleted < 100 ) {
347
- if ( req . body . status === TASK_STATUS . DONE || ! req . body . status ) {
340
+ if ( status === TASK_STATUS . DONE || ! status ) {
348
341
return res . boom . badRequest ( "Task percentCompleted can't updated as status is DONE" ) ;
349
342
}
350
343
}
351
344
352
- if (
353
- ( req . body . status === TASK_STATUS . DONE || req . body . status === TASK_STATUS . VERIFIED ) &&
354
- task . taskData . percentCompleted !== 100
355
- ) {
345
+ if ( ( status === TASK_STATUS . DONE || status === TASK_STATUS . VERIFIED ) && task . taskData . percentCompleted !== 100 ) {
356
346
if ( req . body . percentCompleted !== 100 ) {
357
347
return res . boom . badRequest ( "Status cannot be updated. Task is not done yet" ) ;
358
348
}
359
349
}
360
350
}
361
351
362
352
if ( task . taskData . status === TASK_STATUS . COMPLETED && req . body . percentCompleted < 100 ) {
363
- if ( req . body . status === TASK_STATUS . COMPLETED || ! req . body . status ) {
353
+ if ( status === TASK_STATUS . COMPLETED || ! status ) {
364
354
return res . boom . badRequest ( "Task percentCompleted can't updated as status is COMPLETED" ) ;
365
355
}
366
356
}
367
357
if (
368
- ( req . body . status === TASK_STATUS . COMPLETED || req . body . status === TASK_STATUS . VERIFIED ) &&
358
+ ( status === TASK_STATUS . COMPLETED || status === TASK_STATUS . VERIFIED ) &&
369
359
task . taskData . percentCompleted !== 100
370
360
) {
371
361
if ( req . body . percentCompleted !== 100 ) {
@@ -386,16 +376,16 @@ const updateTaskStatus = async (req, res, next) => {
386
376
} ,
387
377
} ;
388
378
389
- if ( req . body . status && ! req . body . percentCompleted ) {
390
- taskLog . body . new . status = req . body . status ;
379
+ if ( status && ! req . body . percentCompleted ) {
380
+ taskLog . body . new . status = status ;
391
381
}
392
- if ( req . body . percentCompleted && ! req . body . status ) {
382
+ if ( req . body . percentCompleted && ! status ) {
393
383
taskLog . body . new . percentCompleted = req . body . percentCompleted ;
394
384
}
395
385
396
- if ( req . body . percentCompleted && req . body . status ) {
386
+ if ( req . body . percentCompleted && status ) {
397
387
taskLog . body . new . percentCompleted = req . body . percentCompleted ;
398
- taskLog . body . new . status = req . body . status ;
388
+ taskLog . body . new . status = status ;
399
389
}
400
390
401
391
const [ , taskLogResult ] = await Promise . all ( [
@@ -404,7 +394,7 @@ const updateTaskStatus = async (req, res, next) => {
404
394
] ) ;
405
395
taskLog . id = taskLogResult . id ;
406
396
407
- if ( req . body . status ) {
397
+ if ( status ) {
408
398
userStatusUpdate = await updateStatusOnTaskCompletion ( userId ) ;
409
399
}
410
400
return res . json ( {
0 commit comments