Merge branch 'task-116-fix/edit_tasks_author' into 'development'

Task 116 fix/edit tasks author

See merge request !97
parents 0ee7fdf1 b51730d1
......@@ -26,19 +26,17 @@ 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 {user} = 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}
req.body={...req.body,authorStatus:false}
const task = await dataSource
.getRepository(Task)
.findOne({
......@@ -47,28 +45,23 @@ export const authAuthorOrExecutorOfTask = async(req: Request,res: Response, next
author:true,
dateTimeTasks: true,
},
where:[
{
id:taskId,
executor:{
token:token
}
},
where:
{
id:taskId,
author:{
token:token
}
},
]})
})
if (!task) return res.status(404).send({message:'task with possible user involved is not found'})
req.body={...req.body, task:task}
if(task?.executor?.token === token) {
if(task.author?.id===user.id) {
req.body={...req.body,authorStatus:true}
}
if (task.executor?.id===user.id){
req.body={...req.body,executorStatus:true}
}
if (task?.author?.token === token ) {
req.body={...req.body,authorStatus:true}
const {executorStatus, authorStatus} = req.body
if (!executorStatus && !authorStatus) {
res.status(403).send({message:'user is not authorized'})
}
req.body={...req.body, task:task}
next()
};
......@@ -135,9 +128,6 @@ export const authAdminProject = async(req: Request,res: Response, next:NextFunct
}
/** return user if is in the given project, recieves userId adn projectId */
/**task finder by id, return one task */
export const taskFinderById = async (taskId:string):Promise<null | Task>=>{
const task = await dataSource
......@@ -175,7 +165,6 @@ export const taskFinderByDateTimeTaskId = async (dateTimeTaskId:string):Promise<
/**member finder by userId and projectId, return one task */
export const memberFinderById = async (userId:string, projectId:string):Promise<Member|null>=>{
const member = await dataSource
.getRepository(Member)
......
......@@ -305,7 +305,7 @@ router.delete('/:taskId',async (req: Request, res: Response):Promise<Response>=>
/**change of task by task id */
router.put('/:taskId',authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
router.put('/:taskId',auth,authAuthorOrExecutorOfTask,async(req:Request, res:Response)=> {
const {taskId} = req.params
const {authorStatus,executorStatus,title,description,note, archive,project,dateTimeTaskId,dateTimeStart,
dateTimeDue,executor,accomplish,dateTimeDeadLine, dateTimeFactDeadLine,priority} = req.body;
......
......@@ -34,7 +34,6 @@ const TableRowTask= ({
onChange,
onModalOpen,
onProjectChange,
onExecutorChange,
uniqueProjects,
onAuthorChange,
onDateChange,
......@@ -59,6 +58,9 @@ const TableRowTask= ({
const date = moment.utc(dateIso);
return weekDays[date.day()];
}
const calendarOpen=(taskId)=>{
console.log('task Id in Calendar Open' , taskId)
}
return (
<>
......@@ -165,15 +167,15 @@ const TableRowTask= ({
onChange={onDateChange}
user={user}
/> */}
<TableCell>
{/* <TableCell> */}
<Tooltip title="Перейти в календарь">
<IconButton
onClick={(id) => { deleteHandle(task.id);}}
onClick={() => { calendarOpen(task.id)}}
>
<CalendarMonthIcon />
</IconButton>
</Tooltip>
</TableCell>
{/* </TableCell> */}
</TableCell>
) : (
......@@ -209,15 +211,6 @@ const TableRowTask= ({
)}
{/* <TableCell>
<MaterialUIPickers
task={task}
name="dateTimeStart"
onChange={onDateChange}
user={user}
/>
</TableCell> */}
{task.isEditMode && task.author.id===user.id ? (
<TableCell>
<MaterialUIPickers
......@@ -342,31 +335,6 @@ const TableRowTask= ({
{timeTransform(dateTimeTask.dateTimeDue)}
</TableCell>
{/* Edit option datetimeTask */}
<TableCell
// style={{width:'0%'}}
>
{/* <Tooltip title="Редактировать Копию">
{task.isEditMode ? (
<IconButton
aria-label="done"
onClick={() => {
onToggleEditModeDone(dateTimeTask.id);
handleEditDateTimeTask(dateTimeTask);
}}
>
<Done />
</IconButton>
) : (
<IconButton
aria-label="edit"
onClick={() => onToggleEditMode(dateTimeTask.id)}
>
<Edit />
</IconButton>
)}
</Tooltip> */}
</TableCell >
{/* delete option datetimeTask */}
{task.author.id===user.id ?
......
......@@ -152,7 +152,7 @@ export const editTask = (task) => {
return async (dispatch) => {
dispatch(editTaskRequest());
try {
await axios.put("/tasks", task);
await axios.put(`/tasks/${task.id}`, task);
dispatch(editTaskSuccess())
dispatch(fetchAllTasks())
} catch (error) {
......
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