Merge branch 'task-90-fix/delete_edit_dateTiemTask' into 'development'

Task 90 fix/delete edit date tiem task

See merge request !62
parents 8d4ab7da 85008743
......@@ -25,7 +25,14 @@ export const auth = async(req: Request,res: Response, next:NextFunction):Promise
/**Check if user with the given token is executor or author of task with the given Id(taskId) */
export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next:NextFunction):Promise<void | express.Response<Response>>=>{
const token = req.get('Authorization');
const {taskId} = req.body
let taskId = null
taskId = req.body.taskId
if (req.body?.taskId) {
taskId = req.body.taskId
} else if (req.params?.taskId){
taskId = req.params.taskId
} else return res.send({vessage:"there are no taskId found"})
if(!token) return res.status(401).send({Message:'token not exists'})
req.body={...req.body,executorStatus:false}
......@@ -53,15 +60,51 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
},
]})
if (!task) return res.status(404).send({message:'task with possible user involved is not found'})
if(task?.executor?.token === token) {
req.body={...req.body,executorStatus:true}
}
if (task?.author?.token === token ) {
req.body={...req.body,authorStatus:true}
} else if(task?.executor?.token === token) {
req.body={...req.body,executorStatus:true}
} else {
}
next()
};
/**Check if user with the given token is executor or author of task with the given dateTimeTaskId */
export const authAuthorOrExecutorOfDateTimeTask = async(req: Request,res: Response, next:NextFunction):Promise<void | express.Response<Response>>=>{
const token = req.get('Authorization');
let dateTimeTaskId = null
req.body={...req.body,executorStatus:false}
req.body={...req.body,authorStatus:false}
dateTimeTaskId = req.body.dateTimeTaskId
if (req.body?.dateTimeTaskId) {
dateTimeTaskId = req.body.dateTimeTaskId
} else if (req.params?.dateTimeTaskId){
dateTimeTaskId = req.params.dateTimeTaskId
} else return res.send({vessage:"there are no dateTimeTaskId found"})
const task = await dataSource
.createQueryBuilder()
.select(["task"])
.from(Task,"task")
.leftJoinAndSelect("task.executor","user")
.leftJoinAndSelect("task.dateTimeTasks","dateTimeTask")
.leftJoinAndSelect("task.author","users")
.where("dateTimeTask.id = :dateTimeTaskId", {dateTimeTaskId})
.getOne()
if (!task) return res.status(404).send({message:'task with possible user involved is not found'})
if(task?.executor?.token === token) {
req.body={...req.body,executorStatus:true}
}
if (task?.author?.token === token ) {
req.body={...req.body,authorStatus:true}
}
next()
}
/**task finder by id, return one task */
export const taskFinderById = async (taskId:string):Promise<null | Task>=>{
const task = await dataSource
......
......@@ -5,7 +5,7 @@ import { User } from '../models/User';
import { Member } from '../models/Member';
import { In } from 'typeorm';
import { DateTimeTask } from '../models/DateTimeTask';
import { auth, authAuthorOrExecutorOfTask } from '../helpers';
import { auth, authAuthorOrExecutorOfDateTimeTask, authAuthorOrExecutorOfTask } from '../helpers';
const router:Router = express.Router();
const dataSource = myDataSource;
......@@ -42,7 +42,7 @@ router.post("/make-copy", async(req:Request, res:Response):Promise<Response>=>{
/** change date time of copy of task in calendar view */
router.put("/change-copy", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{
const {dateTimeTaskId, taskId, dateTimeStart, dateTimeDue, description, title, priority} = req.body
const {executorStatus, dateTimeTaskId, taskId, dateTimeStart, dateTimeDue, description, title, priority} = req.body
const dateTimeTask = await dataSource
.createQueryBuilder()
.select('dateTimeTask')
......@@ -63,8 +63,9 @@ router.put("/change-copy", authAuthorOrExecutorOfTask, async(req:Request, res: R
})
/**delete copyTask by dateTimeTaskId */
router.delete('/:dateTimeTaskId', async(req:Request, res:Response):Promise<Response>=>{
// router.delete('/:dateTimeTaskId', authAuthorOrExecutorOfTask, async(req:Request, res:Response):Promise<Response>=>{
router.delete('/:dateTimeTaskId',authAuthorOrExecutorOfDateTimeTask, async(req:Request, res:Response):Promise<Response|void>=>{
const {executorStatus} = req.body
if(executorStatus){
const {dateTimeTaskId} = req.params
await myDataSource
.createQueryBuilder()
......@@ -74,6 +75,7 @@ router.delete('/:dateTimeTaskId', async(req:Request, res:Response):Promise<Respo
.execute()
return res.send({message:"copyTask delete succesfully"})
}
}
)
export default router;
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