#151 added try blocks to copyTasks.ts

parent 9e80d81e
......@@ -9,6 +9,7 @@ const dataSource = myDataSource;
/** make copy of task in calendar view */
router.post("/make-copy",auth,authAuthorOrExecutorOfTask, async(req:Request, res:Response):Promise<Response>=>{
try{
const {taskId, dateTimeDue, dateTimeStart, authorStatus, executorStatus, task} = req.body;
if(!task) return res.status(401).send({message:'task with possible user involved is not found'})
const newDateTimeTask = new DateTimeTask();
......@@ -17,10 +18,14 @@ router.post("/make-copy",auth,authAuthorOrExecutorOfTask, async(req:Request, res
newDateTimeTask.task = taskId;
await newDateTimeTask.save();
return res.send({task, message:"copyTask created!"})
} catch(e) {
return res.status(502).send({message:(e as Error).message})
}
} )
/** change date time of copy of task in calendar view */
router.put("/change-copy/:dateTimeTaskId",auth, authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{
try{
const {dateTimeTaskId} = req.params
const {executorStatus,authorStatus, task, dateTimeStart, dateTimeDue, description, title, priority, project} = req.body
if(authorStatus){
......@@ -76,10 +81,14 @@ router.put("/change-copy/:dateTimeTaskId",auth, authAuthorOrExecutorOfTask, asyn
task.project = project
await task.save()
return res.send({task})
} catch(e) {
return res.status(502).send({message:(e as Error).message})
}
})
/**delete copyTask by dateTimeTaskId */
router.delete('/:dateTimeTaskId',authAuthorOrExecutorOfDateTimeTask, async(req:Request, res:Response):Promise<Response|void>=>{
try{
const {authorStatus, executorStatus, task} = req.body
const {dateTimeTaskId} = req.params
......@@ -117,6 +126,9 @@ router.delete('/:dateTimeTaskId',authAuthorOrExecutorOfDateTimeTask, async(req:R
return res.send({message:"not uathorized to delete task"})
}
}
} catch(e) {
return res.status(502).send({message:(e as Error).message})
}
}
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment