#151 added try blocks to copyTasks.ts

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