#101 fix fetch projects after delete

parent 959d2099
...@@ -143,17 +143,32 @@ router.post('/add-user/', authAdminProject, async (req: Request, res: Response): ...@@ -143,17 +143,32 @@ router.post('/add-user/', authAdminProject, async (req: Request, res: Response):
/** Remove user from specific project by userId */ /** Remove user from specific project by userId */
router.delete('/remove-user/:userId', authAdminProject,async (req: Request, res: Response):Promise<Response>=> { router.delete('/remove-user/:userId', authAdminProject,async (req: Request, res: Response):Promise<Response>=> {
console.log('req ', req) console.log('req.body ', req.body)
const {projectId} = req.body.data; const {projectId} = req.body;
const {userId }=req.params; const {userId }=req.params;
console.log('projectId ', projectId, 'userId ',userId )
try{ try{
await dataSource const projectMember = await dataSource
.createQueryBuilder() .getRepository(Member)
.delete() .findOne({
.from(Member) relations:{
.where("user= :userId", { userId }) user:true,
.andWhere("project=:projectId",{projectId}) project:true
.execute() },
where:{
user:{
id:userId
},
project:{
id:projectId
}
}
})
console.log('projectMember ', projectMember)
if(!projectMember) return res.status(404).send({message:"this member is not present"})
await Member.delete({id:projectMember.id})
console.log('projectMember deleted successfully')
return res.send({message:"User removed from project successfully" }) return res.send({message:"User removed from project successfully" })
} catch(e){ } catch(e){
return res.send({message:'Failed to remove user from project'}) return res.send({message:'Failed to remove user from project'})
......
...@@ -40,9 +40,9 @@ const deleteMemberRequest = () => { ...@@ -40,9 +40,9 @@ const deleteMemberRequest = () => {
dispatch(deleteMemberRequest()); dispatch(deleteMemberRequest());
try { try {
const response = await axios.delete(`/projects/remove-user/${memberId}`, { data: { projectId: projectId}}); const response = await axios.delete(`/projects/remove-user/${memberId}`, { data: { projectId: projectId}});
console.log(response.data) console.log("deleteMember ", response.data)
dispatch(deleteMemberSuccess()) dispatch(deleteMemberSuccess())
dispatch(fetchProject()) dispatch(fetchProject(projectId))
} catch (error) { } catch (error) {
dispatch(deleteMemberFailure(error.response.data)); dispatch(deleteMemberFailure(error.response.data));
} }
......
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